Skip to content

Commit

Permalink
Image Copyright logo
Browse files Browse the repository at this point in the history
  • Loading branch information
emaillenin committed Dec 3, 2014
1 parent 467fd3c commit cb5779e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 67 deletions.
57 changes: 35 additions & 22 deletions index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,47 @@

puts "#{src.columns}x#{src.rows}"

start_x = template.copyright['x_offset']
start_y = (src.rows/2) - template.copyright['height']
end_x = start_x + template.copyright['width']
end_y = (src.rows/2) + template.copyright['height']

imgl.from_blob(File.open(template.image['path']).read)

copyright_box = Magick::Draw.new
copyright_box.fill_opacity(template.copyright['opacity'])
copyright_box.rectangle(start_x, start_y, end_x, end_y)
copyright_box.font(template.copyright['font'])
copyright_box.draw(imgl)

imgl.alpha(Magick::ActivateAlphaChannel)

output = "#{File.dirname(template.image['path'])}/mojo_#{File.basename(template.image['path'])}"

watermark_text = Magick::Draw.new
watermark_text.annotate(imgl, start_x, start_y, end_x - 5, end_y - 10, template.copyright['text']) do
self.gravity = Magick::EastGravity
self.pointsize = 15
self.font_family = 'Serif'
self.font_weight = Magick::BoldWeight
self.stroke = 'transparent'
self.fill = 'white'
self.rotation = 270
self.kerning = 1
self.align = LeftAlign
logo_overlay = ImageList.new("./assets/images/#{template.image_copyright['file']}")
imgl.gravity= Magick.const_get(template.image_copyright['location'])
imgl.geometry='0x0+10+10'
rails_on_ruby = imgl.composite_layers(logo_overlay, Magick::OverCompositeOp)
rails_on_ruby.format = 'png'
rails_on_ruby.write(output)

imgl.clear
imgl.from_blob(File.open(output).read)

if !template.copyright.nil? && template.copyright['show']

start_x = template.copyright['x_offset']
start_y = (src.rows/2) - template.copyright['height']
end_x = start_x + template.copyright['width']
end_y = (src.rows/2) + template.copyright['height']

copyright_box = Magick::Draw.new
copyright_box.fill_opacity(template.copyright['opacity'])
copyright_box.rectangle(start_x, start_y, end_x, end_y)
copyright_box.font(template.copyright['font'])
copyright_box.draw(imgl)

watermark_text = Magick::Draw.new
watermark_text.annotate(imgl, start_x, start_y, end_x - 5, end_y - 10, template.copyright['text']) do
self.gravity = Magick::EastGravity
self.pointsize = 15
self.font_family = 'Serif'
self.font_weight = Magick::BoldWeight
self.stroke = 'transparent'
self.fill = 'white'
self.rotation = 270
self.kerning = 1
self.align = LeftAlign
end
end

imgl.write(output)
Expand Down
5 changes: 3 additions & 2 deletions src/image_annotate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def apply_template
background_caption = Magick::Draw.new
background_caption.opacity(caption['background_opacity'])
background_caption.fill(caption['background_color'])
background_caption.stroke_opacity(0)
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)
Expand All @@ -22,9 +23,9 @@ def apply_template
self.pointsize = caption['size']
self.font_family = caption['font']
self.font_weight = Magick::BoldWeight
self.stroke = 'transparent'
# self.stroke = 'transparent'
self.fill = caption['color']
self.stroke = caption['stroke'] || caption['color']
# self.stroke = caption['stroke'] || caption['color']
self.stroke_width = caption['stroke_width'] || 1
self.font_weight = Magick::BoldWeight
# self.rotation = 270
Expand Down
3 changes: 2 additions & 1 deletion src/template/image_mojo_template.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
require 'psych'
class ImageMojoTemplate

attr_accessor :all_templates, :copyright, :caption, :image, :hashtag
attr_accessor :all_templates, :copyright, :caption, :image, :hashtag, :image_copyright
def initialize(config_file)
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']
@image_copyright = @all_templates['image_copyright']
end
end
60 changes: 18 additions & 42 deletions template.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,34 @@

image:
path: /Users/leninraj/Downloads/kohli.jpg
path: /Users/leninraj/Downloads/hughes.jpg

copyright:
text: WWW.DUGGOUT.COM
height: 100
width: 25
x_offset: 25
opacity: 0.6
font: Roboto
image_copyright:
file: logo.png
location: NorthEastGravity

hashtag:
text: IndVsWI
hhashtag:
text: AusVsSA
x_offset: 25
y_offset: 25
font: Roboto
color: white

caption_player:
text: Kohli - 62
line_spacing: 5
player:
text: "Australia win series\n4-1"
line_spacing: 10
blur: 0.4
font: Futura Today
font: Serif
size: 60
color: white
stroke_width: 1
offset_x: 260
offset_y: -400
background: false
# background_color: rgba(150,93,14,0.8) # brown
# background_color: rgba(255,255,255,0.8) # white
# background_color: rgba(10,10,10,0.6) # black
background_color: rgba(23,168,230,0.9) # blue
# background_color: rgba(150,14,93,0.5) # pink
background_opacity: 0.6
background_height: 140
background_start_y: 840

caption_info:
text: ODI HALF-CENTURY\nafter a break of 8 innings!\nHis longest break\nsince his DEBUT!!
line_spacing: 5
blur: 0.4
font: Futura Today
size: 50
color: white
stroke_width: 1
offset_x: 0
offset_y: 400
offset_y: 214
quote: false
background: true
# background_color: rgba(150,93,14,0.8) # brown
# background_color: rgba(150,93,14,0.9) # brown
# background_color: rgba(255,255,255,0.8) # white
# background_color: rgba(10,10,10,0.6) # black
background_color: rgba(23,168,230,0.9) # blue
background_color: rgba(10,10,10,0.9) # black
# background_color: rgba(23,168,230,1) # blue
# background_color: rgba(150,14,93,0.5) # pink
background_opacity: 0.6
background_height: 250
background_start_y: 920
background_opacity: 0.9
background_height: 350
background_start_y: 450

0 comments on commit cb5779e

Please sign in to comment.