-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstracted out image annotation so multiple captions can be supported
- Loading branch information
1 parent
02be2e9
commit b790deb
Showing
7 changed files
with
162 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'rmagick' | ||
|
||
gem 'psych' | ||
gem 'psych', '2.0.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
psych (2.0.0) | ||
rmagick (2.13.2) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
psych | ||
rmagick |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class ImageAnnotate | ||
def initialize(source_image,image_list, caption) | ||
@caption = caption | ||
@image_list = image_list | ||
@source_image = source_image | ||
end | ||
|
||
def apply_template | ||
caption = @caption | ||
if caption['background'] | ||
background_caption = Magick::Draw.new | ||
background_caption.opacity(caption['background_opacity']) | ||
background_caption.fill(caption['background_color']) | ||
background_caption.rectangle(0, caption['background_start_y'], @source_image.columns, caption['background_start_y'] + caption['background_height']) | ||
background_caption.draw(@image_list) | ||
@image_list.alpha(Magick::ActivateAlphaChannel) | ||
end | ||
|
||
caption_text = Magick::Draw.new | ||
caption_text.annotate(@image_list, @source_image.columns, @source_image.rows, @source_image.columns/2 + caption['offset_x'], @source_image.rows/2 + caption['offset_y'], caption['text']) do | ||
self.gravity = Magick::CenterGravity | ||
self.pointsize = caption['size'] | ||
self.font_family = caption['font'] | ||
self.font_weight = Magick::BoldWeight | ||
self.stroke = 'transparent' | ||
self.fill = caption['color'] | ||
self.stroke = caption['stroke'] | ||
self.stroke_width = 1 | ||
self.font_weight = Magick::BoldWeight | ||
# self.rotation = 270 | ||
self.kerning = 1 | ||
self.interline_spacing = 7 | ||
self.align = CenterAlign | ||
end | ||
@image_list | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
require 'psych' | ||
class ImageMojoTemplate | ||
|
||
attr_accessor :copyright, :caption, :image | ||
attr_accessor :all_templates, :copyright, :caption, :image, :hashtag | ||
def initialize(config_file) | ||
template = Psych.load(File.read(config_file)) | ||
@copyright = template['copyright'] | ||
@caption = template['caption'] | ||
@image = template['image'] | ||
puts "Using template file #{config_file}" | ||
@all_templates = Psych.load(File.read(config_file)) | ||
@copyright = @all_templates['copyright'] | ||
@caption = @all_templates['caption'] | ||
@image = @all_templates['image'] | ||
@hashtag = @all_templates['hashtag'] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
image: | ||
path: /Users/leninraj/Downloads/virat.jpg | ||
|
||
copyright: | ||
text: WWW.DUGGOUT.COM | ||
height: 100 | ||
width: 25 | ||
x_offset: 25 | ||
opacity: 0.6 | ||
font: Roboto | ||
|
||
hashtag: | ||
text: ENGvsIND | ||
x_offset: 25 | ||
y_offset: 25 | ||
font: Roboto | ||
|
||
caption_player: | ||
text: VIRAT KOHLI | ||
font: Roboto | ||
size: 80 | ||
color: white | ||
stroke: white | ||
offset_x: 0 | ||
offset_y: 422 | ||
background: true | ||
background_color_brown: rgba(150,93,14,0.4) | ||
background_color_white: rgba(225,225,243,0.4) | ||
background_color_black: rgba(10,10,10,0.4) | ||
background_color: rgba(23,168,230,0.7) # blue | ||
background_color_pink: rgba(150,14,93,0.5) | ||
background_opacity: 0.2 | ||
background_height: 100 | ||
background_start_y: 990 | ||
|
||
caption_1st_innings: | ||
text: 1st MATCH - 1 AND 8 | ||
font: Roboto | ||
size: 50 | ||
color: white | ||
stroke: white | ||
offset_x: 0 | ||
offset_y: 512 | ||
background: true | ||
background_color: rgba(150,93,14,0.6) # brown | ||
background_color_white: rgba(225,225,243,0.4) | ||
background_color_black: rgba(10,10,10,0.4) | ||
background_color_blue: rgba(23,168,230,0.7) # blue | ||
background_color_pink: rgba(150,14,93,0.5) | ||
background_opacity: 0.2 | ||
background_height: 100 | ||
background_start_y: 1090 | ||
|
||
caption_2nd_innings: | ||
text: 2nd MATCH - 25 AND 0 | ||
font: Roboto | ||
size: 50 | ||
color: white | ||
stroke: white | ||
offset_x: 0 | ||
offset_y: 612 | ||
background: true | ||
background_color: rgba(150,93,14,0.6) | ||
background_color_white: rgba(225,225,243,0.4) | ||
background_color_black: rgba(10,10,10,0.4) | ||
background_color_blue: rgba(23,168,230,0.7) # blue | ||
background_color_pink: rgba(150,14,93,0.5) | ||
background_opacity: 0.2 | ||
background_height: 100 | ||
background_start_y: 1190 |