Search code examples
rubyimagemagickminimagick

Write a string with caption method using MiniMagick


I'm trying to write a string over a image. Currently I'm using MiniMagick and I can resize and overlap two images, but when I try write a multiline string using caption nothing happens to final image, it's still same as before.

Here is my current code:

image = MiniMagick::Image.open('template.jpg')
image.combine_options do |c|
  c.background '#0008'
  c.fill '#666'
  c.gravity 'center'
  c.size '100x50'
  c.caption "Lets write some big string here... zzzzz I hope this work =)"
end
image.write('final.jpg')

My refs: http://www.imagemagick.org/Usage/annotating/

ImageMagick multiline text and background image

http://www.imagemagick.org/www/command-line-options.html#caption

Thanks all


Solution

  • I ended using a system call to get rid this problem, here is the code:

    Subexec.run "convert -background '#fff0' \\
      -fill '#003300' \\
      -gravity west \\
      -size 560x180 \\
      -pointsize 19 \\
      -font \'#{font_path}\' \\
      caption:\"#{caption}\" \\
      #{photo_path} \\
      +swap \\
      -gravity NorthWest \\
      -geometry +333+113 \\
      -composite #{photo_path}"