-
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.
- Loading branch information
1 parent
5f466ed
commit 0aba81d
Showing
5 changed files
with
98 additions
and
0 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,5 +1,6 @@ | ||
*.gem | ||
*.rbc | ||
.idea | ||
/.config | ||
/coverage/ | ||
/InstalledFiles | ||
|
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,3 @@ | ||
gem 'rmagick' | ||
|
||
gem 'psych' |
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,64 @@ | ||
require 'RMagick' | ||
include Magick | ||
|
||
require_relative 'src/template/image_mojo_template' | ||
|
||
template = ImageMojoTemplate.new(ARGV[0]) | ||
|
||
imgl = Magick::ImageList.new | ||
|
||
src = Magick::Image.read(template.image['path']).first | ||
|
||
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) | ||
|
||
gc = Magick::Draw.new | ||
|
||
gc.fill_opacity(template.copyright['opacity']) | ||
|
||
gc.rectangle(start_x, start_y, end_x, end_y) | ||
|
||
gc.font(template.copyright['opacity']) | ||
|
||
gc.draw(imgl) | ||
|
||
imgl.alpha(Magick::ActivateAlphaChannel) | ||
|
||
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 = 'Arial' | ||
self.font_weight = Magick::BoldWeight | ||
self.stroke = 'transparent' | ||
self.fill = 'white' | ||
self.rotation = 270 | ||
self.kerning = 1 | ||
self.align = LeftAlign | ||
end | ||
|
||
caption_text = Magick::Draw.new | ||
caption_text.annotate(imgl, src.columns, src.rows, src.columns/2, src.rows/2, template.caption['text']) do | ||
self.gravity = Magick::CenterGravity | ||
self.pointsize = template.caption['size'] | ||
self.font_family = template.caption['font'] | ||
self.font_weight = Magick::BoldWeight | ||
self.stroke = 'transparent' | ||
self.fill = template.caption['color'] | ||
self.stroke = template.caption['stroke'] | ||
self.stroke_width = 1 | ||
# self.rotation = 270 | ||
self.kerning = 1 | ||
self.interline_spacing = 2.5 | ||
self.align = CenterAlign | ||
end | ||
|
||
imgl.write("mojo_#{File.basename(template.image['path'])}") | ||
|
||
exit |
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,11 @@ | ||
require 'psych' | ||
class ImageMojoTemplate | ||
|
||
attr_accessor :copyright, :caption, :image | ||
def initialize(config_file) | ||
template = Psych.load(File.read(config_file)) | ||
@copyright = template['copyright'] | ||
@caption = template['caption'] | ||
@image = template['image'] | ||
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
image: | ||
path: /Users/leninraj/Downloads/161895.3.jpg | ||
|
||
copyright: | ||
text: WWW.DUGGOUT.COM | ||
height: 100 | ||
width: 25 | ||
x_offset: 50 | ||
opacity: 0.6 | ||
font: Roboto | ||
|
||
caption: | ||
text: Chris Gayle is playing his \n100th test match today! | ||
font: Roboto | ||
size: 45 | ||
color: white | ||
stroke: Transparent | ||
offset_x: 0 | ||
offset_y: 100 |