Skip to content

Commit

Permalink
Removing dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
emaillenin committed Dec 26, 2014
1 parent 521b64d commit f905fcf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 46 deletions.
58 changes: 15 additions & 43 deletions index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,32 @@

template = ImageMojoTemplate.new(ARGV[0])

imgl = Magick::ImageList.new

src = Magick::Image.read(template.image['path']).first
base_image_path = template.image['path']
src = Magick::Image.read(base_image_path).first

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

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

imgl.alpha(Magick::ActivateAlphaChannel)
image_list = Magick::ImageList.new
image_list.from_blob(File.open(base_image_path).read)
image_list.alpha(Magick::ActivateAlphaChannel)

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

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)
image_list.gravity= Magick.const_get(template.image_copyright['location'])
image_list.geometry='0x0+10+10'
rails_on_ruby = image_list.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
image_list.clear
image_list.from_blob(File.open(output).read)

imgl.write(output)
image_list.write(output)

unless template.hashtag.nil?
watermark_text = Magick::Draw.new
watermark_text.annotate(imgl, 0, 0, 10, 25, "##{template.hashtag['text']}") do
watermark_text.annotate(image_list, 0, 0, 10, 25, "##{template.hashtag['text']}") do
self.gravity = Magick::EastGravity
self.pointsize = 18
self.font_family = template.hashtag['font']
Expand All @@ -72,10 +44,10 @@


template.all_templates.keys.select { |key| key.to_s.start_with?('caption') }.each do |caption|
a = ImageAnnotate.new(src, imgl, template.all_templates[caption])
a = ImageAnnotate.new(src, image_list, template.all_templates[caption])
a.apply_template
puts "Writing to #{output}"
imgl.write(output)
image_list.write(output)
end


Expand Down
4 changes: 1 addition & 3 deletions src/template/image_mojo_template.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
require 'psych'
class ImageMojoTemplate

attr_accessor :all_templates, :copyright, :caption, :image, :hashtag, :image_copyright
attr_accessor :all_templates, :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']
Expand Down

0 comments on commit f905fcf

Please sign in to comment.