Search code examples
imagemagickimagemagick-convert

ImageMagick - convert different results on two different servers


I'm using the below command in order to generate a coupon image. In my dev environment I'm using Ubuntu Server and in production I'm using Centos 7.

convert 
-font /some-path/Gotham-Ultra.ttf 
-gravity center 
-geometry +0-0 
-background none 
-gravity south 
-fill #FC3B45 
-size 330x90 
caption:VIERNES 
-font Helvetica-Bold 
-gravity north 
-background none 
-pointsize 25 
-fill #671646 
-size 330x 
caption:–––––––––––––––––––– 
-font /some-path/Gotham-Ultra.ttf 
-gravity center 
-background none 
-fill #671646 
-size 330x210 
+pointsize 
caption:4 EMPANADAS 2 PORCIONES DE ENSALADAS 2 REFRESCOS DE 355ML POR $195 
-font Helvetica-Bold 
-gravity north 
-background none 
-pointsize 25 
-fill #671646 
-size 330x 
caption:–––––––––––––––––––– 
-append /some-path/canvas/yellow.png 
+swap 
-gravity center 
-composite /some-path/photo.jpg 
-crop 450x480+0+0 
+swap 
-append 
/tmp/coupon_image20180212-7979-p52o3f.jpg

So, I expect that the caption will resize the font automatically based on the space given as per: http://www.imagemagick.org/Usage/text/#caption_bestfit

This is my output in my prod env:

Centos 7 (Production)

enter image description here

And I expect the following:

Ubuntu Server (Dev)

enter image description here

The only difference for now is the ImageMagick version:

Prod:

Version: ImageMagick 6.7.8-9 2016-06-16 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP

Dev:

Version: ImageMagick 6.7.7-10 2016-06-01 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP

What do you recommend guys? Should I match the versions? (downgrade in production) Is there other options available?


Solution

  • Your code has some problems as listed above. On Unix, you need end of line \. You have listed the photo.jpg but provided img.jpg. You used -append at the end, but it should be +append. On Unix, you must put quotes about your label text and about hex colors. So the proper listing for your code is as follows. Change the paths to your files and names and path to your fonts as desired.

    convert \
    -font /Library/fonts/Gotham-Ultra.ttf \
    -gravity center \
    -geometry +0-0 \
    -background none \
    -gravity south \
    -fill "#FC3B45" \
    -size 330x90 \
    caption:VIERNES \
    -font /Library/fonts/Helvetica-Bold.ttf \
    -gravity north \
    -background none \
    -pointsize 25 \
    -fill "#671646" \
    -size 330x \
    caption:"––––––––––––––––––––" \
    -font /Library/fonts/Gotham-Ultra.ttf \
    -gravity center \
    -background none \
    -fill "#671646" \
    -size 330x210 \
    +pointsize \
    caption:"4 EMPANADAS 2 PORCIONES DE ENSALADAS 2 REFRESCOS DE 355ML POR $195" \
    -font /Library/fonts/Helvetica-Bold.ttf \
    -gravity north \
    -background none \
    -pointsize 25 \
    -fill "#671646" \
    -size 330x \
    caption:"––––––––––––––––––––" \
    -append \
    yellow.png \
    +swap \
    -gravity center \
    -composite \
    photo.jpg \
    -crop 450x480+0+0 \
    +repage \
    +swap \
    +append \
    coupon_image20180212-7979-p52o3f.jpg
    

    Where I have put the images in the same directory location as running the command line. I have also added +repage after the crop.

    Nevertheless, IM 6.7.8.9 is buggy. I can reproduce your bad results for that version. I get the proper results for IM 6.9.9.34 Q16 MacOS Sierra, the current version and for IM 6.7.7.10 and IM 6.8.6.8 (the next version I had handy). IM 6.7.8.9 has proven to me to be buggy in a number of ways. It was a poor choice for the Linux distros, in my opinion. You should look into an upgrade if possible.