5

I'm learning to use ImageMagick, but I'm having trouble when I try to generate an image like the example below:

ImageMagick Example

And for that, I'm using the following code:

convert original.jpg -size 460x caption:'This is a multiline caption, This is a multiline caption, This is a multiline caption.' result.jpg

This command generated two separate images, one with just the title. Can you help me?


PS: I'm using RubyOnRails with ImageMagick, but you can suggest examples with MiniMagick or Rmagick. Thanks.

Caio Tarifa
  • 5,973
  • 11
  • 46
  • 73

1 Answers1

7

This works in php and I can not see why it will not work o RubyOnRails:

convert original.jpg -size 460x -background transparent -fill black -pointsize 40 caption:'This is a multiline caption, This is a multiline caption, This is a multiline caption.'  -gravity center -composite result.jpg
Bonzo
  • 5,169
  • 1
  • 19
  • 27
  • Just thinking about it the text is not centered on the caption; just the caption on the photo. I did not think this would work but adding a -gravity to the caption works for me. convert original.jpg -size 460x -background transparent -fill black -pointsize 45 -gravity center caption:'This is a multiline caption, This is a multiline caption, This is a multiline caption.' -gravity center -composite result.jpg – Bonzo Apr 27 '12 at 16:47
  • Thanks @Bonzo, worked perfectly, you could tell me how I can positioning this block of text at X: 50 and Y: 80? :D – Caio Tarifa Apr 27 '12 at 17:06
  • A problem with Imagemagick ( Should be sorted in Version 7 ) is the -geometry and -gravity of the text and image placement interfer with each other. It would be difficault to say have centered text and then the text placed at a certain point on the image with this method. For what you want this should work although the text is aligned to the left now. convert original.jpg -size 460x -background transparent -fill black -pointsize 45 caption:'This is a multiline caption, This is a multiline caption, This is a multiline caption.' -geometry +50+80 -composite result1.jpg – Bonzo Apr 27 '12 at 17:35
  • Nice. Thanks! To generate dynamic images with text I was trying to generate a pdf, converting it to a png and merging it with my image. With that it's a lot easier. The only thing I need in addition is to use an custom font. Is that possible? Or do I have to stay with my pdf? – Yves Nov 28 '14 at 17:27
  • Just upload your font and use -font path/to/font/font.ttf before the caption – Bonzo Dec 02 '14 at 18:51