Massive differences in rendering between different versions

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
eepstein

Massive differences in rendering between different versions

Post by eepstein »

I have a server in production using 6.5.6.4 and everything is going very well. In order to deal with some very high demands on our server, which happens only occasionally, we are going to keep a presence on Amazon's EC2 to be able to scale up and down cost effectively.

So I have had to build a VM from scratch here. I already got the latest version 6.6.2-4 installed and I can't go back to 6.5.6.4, I TRIED.
coders/png.c:9090: warning: format `%lu' expects type `long unsigned int', but argument 6 has type `unsigned int'
coders/png.c:9093: warning: format `%lu' expects type `long unsigned int', but argument 6 has type `unsigned int'
make[1]: *** [coders/coders_png_la-png.lo] Error 1
make[1]: Leaving directory `/usr/src/imagemagick/ImageMagick-6.5.6-10'
make: *** [all] Error 2
There is just massive differences in the rendering of the images between these two versions, all of it for the worse. Quite frankly it reminds me of trying to code CSS and getting it to work right with IE/Firefox at the same time :P

Everything we do is command line. No API.

1) It seems that all of geometry is offset upwards and towards the left. (I could change my offsets)
2) All of the text is now tighter together. (I could live with that)
3) The rounded borders I had created before now look like terrible. (Can't live with the complaints)

Here is an example of the code I am using to create the rounded borders:

Code: Select all

/usr/bin/convert example.png  -quality 100 \( +clone  -threshold -1 -draw 'fill black polygon 0,0 0,10 10,0 fill white circle 10,10 10,0' \( +clone -flip \) -compose Multiply -composite \( +clone -flop \) -compose Multiply -composite \) +matte -compose CopyOpacity -composite  example_prepared.png
/usr/bin/convert example.png -quality 100 -bordercolor linen -border 6x6 example_prepared.png
/usr/bin/convert example_prepared.png  -quality 100 \( +clone  -threshold -1 -draw 'fill black polygon 0,0 0,15 15,0 fill white circle 15,15 15,0' \( +clone -flip \) -compose Multiply -composite \( +clone -flop \) -compose Multiply -composite \) +matte -compose CopyOpacity -composite  example_prepared.png
/usr/bin/convert example_prepared.png  -quality 100 -matte -virtual-pixel transparent -channel A -blur 0x3  -level 0,50% +channel example_prepared.png
/usr/bin/composite  -quality 100 -gravity Center -geometry +0+35 example_prepared.png final.jpg final.jpg
What the code creates is really different between the versions:

Good Image (nice rounded borders that are faded and 3d like. Similar to pillow emboss in Photoshop):

Image

Bad Image (sides are not faded at all and there seems to be an aborted attempt at fading the edges):

Image

Any idea as to what has changed between the versions? Or why I can't install the older version over the newer one? I would prefer to get it working with the new version instead of being held hostage to old code. Not a good strategy.

Your ideas and help is greatly appreciated! Ohh, and thank you very much to the creators of and the contributors to ImageMagick.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Massive differences in rendering between different versi

Post by snibgo »

You have some complicated code. It would be really helpful if you could provide the input image that gives those outputs. Otherwise, we can only guess.

Running multiple versions is really easy under Windows. (Just install to different directories, and use environment variables to specify which version you want.) I guess it is also easy on other platforms, but I can't advise you there.

EDIT: "-gravity" has a default of "northwest", which might cause your problem (1). If so, try "-gravity center".

EDIT2: I notice that your first convert creates "example_prepared.png", and so does your second. So the first convert is redundant. I also notice that your final convert changes "final.jpg" (rather than creating a new one). So running the sequence twice won't give the same result. In particular, you will be blurring a blur.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Massive differences in rendering between different versi

Post by snibgo »

The only significant difference between your images seems to be the blurring on the outside of the white border.

Looking further at your script, consider the convert command:

Code: Select all

/usr/bin/convert
  example_prepared.png \
  -quality 100 \
  -matte -virtual-pixel transparent \
  -channel A -blur 0x3 \
  -level 0,50% +channel \
  example_prepared.png
Assume the input has alpha=255/255 along most of the borders (except the corners). Then the blur will cause alpha within the image (except the corners) to be at least 128/255. The "-level 0,50%" will cause all values above 128/255 to become 255. So this will remove the blur along most of the edge.

I conclude that if this script with a previous version of IM blurred the entire edge, it was caused by a bug which has been fixed. You can get the blur by removing "-level 0,50%". The "+channel" is redundant.
snibgo's IM pages: im.snibgo.com
eepstein

Re: Massive differences in rendering between different versi

Post by eepstein »

Thank you very much for your reply.
Running multiple versions is really easy under Windows. (Just install to different directories, and use environment variables to specify which version you want.) I guess it is also easy on other platforms, but I can't advise you there.
Using CentOS, so it is not very easy to run multiple versions. I can't even get the older version to compile.
EDIT: "-gravity" has a default of "northwest", which might cause your problem (1). If so, try "-gravity center".
After reviewing all of my code, I am specifying "Center" each time. I changed it to the lowercase "center" in your example with no differences in output.
EDIT2: I notice that your first convert creates "example_prepared.png", and so does your second. So the first convert is redundant. I also notice that your final convert changes "final.jpg" (rather than creating a new one). So running the sequence twice won't give the same result. In particular, you will be blurring a blur.
I was redacting out some production code to make it easier to view. The 2nd line of code is incorrect. Only the first line starts with example.png, the rest operate on example_prepared.png.

What do you mean by running the sequence twice? The last convert does not operate on final.jpg, but on example_prepared.png. Should I be running the last two converts on the same line?

You said "rather than create a new one". The last command is a composite where I take the example_prepared.png and overlay it on top of another image. Should I be writing the composite command differently?
I conclude that if this script with a previous version of IM blurred the entire edge, it was caused by a bug which has been fixed. You can get the blur by removing "-level 0,50%". The "+channel" is redundant.
Following your suggestion on removing the code worked for everything but the corners. How would I get the corners to have the rounded edges like before?

Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Massive differences in rendering between different versi

Post by snibgo »

The first convert takes one input image (example.png) and makes one output (example_prepared.png). The second convert takes the same input file (example.png) and makes one output (example_prepared.png). The output of the second will overwrite the output of the first. You can remove the first convert without affecting the final result.

The final composite takes two inputs (example_prepared.png and final.jpg) and writes one output (final.jpg). Thus it overwrites final.jpg. So if you run the command twice, the second output will be different from the first. This doesn't mean it is wrong, but it may be confusing.

"Center" and "center" are the same. IM isn't case sensitive.

All the converts and the final composite can probably be combined into a single command. However, it is best to get it working first.

It would be really helpful if you could provide your input files (example.png and final.jpg).
snibgo's IM pages: im.snibgo.com
eepstein

Re: Massive differences in rendering between different versi

Post by eepstein »

The first convert takes one input image (example.png) and makes one output (example_prepared.png). The second convert takes the same input file (example.png) and makes one output (example_prepared.png). The output of the second will overwrite the output of the first. You can remove the first convert without affecting the final result.
I incorrectly redacted my production code. Example.png is only used as the input once.
The final composite takes two inputs (example_prepared.png and final.jpg) and writes one output (final.jpg). Thus it overwrites final.jpg. So if you run the command twice, the second output will be different from the first. This doesn't mean it is wrong, but it may be confusing.
I am not running the composite command twice. Here is the code redacted again (with your changes):

Code: Select all

/usr/bin/convert portrait.jpg -quality 100  -gravity center -resize '180x270^' portrait_prepared.png
/usr/bin/convert portrait_prepared.png  -quality 100 \( +clone  -threshold -1 -draw 'fill black polygon 0,0 0,10 10,0 fill white circle 10,10 10,0' \( +clone -flip \) -compose Multiply -composite \( +clone -flop \) -compose Multiply -composite \) +matte -compose CopyOpacity -composite  portrait_prepared.png
/usr/bin/convert portrait_prepared.png -quality 100 -bordercolor linen -border 6x6 portrait_prepared.png
/usr/bin/convert portrait_prepared.png  -quality 100 \( +clone  -threshold -1 -draw 'fill black polygon 0,0 0,15 15,0 fill white circle 15,15 15,0' \( +clone -flip \) -compose Multiply -composite \( +clone -flop \) -compose Multiply -composite \) +matte -compose CopyOpacity -composite portrait_prepared.png
/usr/bin/convert portrait_prepared.png  -quality 100 -matte -virtual-pixel transparent -channel A -blur 0x3  portrait_prepared.png
/usr/bin/composite  -quality 100 -gravity Center -geometry +0+35 portrait_prepared.png background.jpg background.jpg
It would be really helpful if you could provide your input files (example.png and final.jpg).
Here they are as portrait.jpg which is the input, and background.jpg which is the background of which the portrait is intended to be overlayed on.

Image

Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Massive differences in rendering between different versi

Post by snibgo »

As I noted in a post above, the blur will cause alpha within the image (except the corners) to be at least 128/255. They will be between 50% and 100%. (You can verify this with a program such as Gimp.) If you want to spread these values to between 0% to 100%, you can put "-level 50%,100%" after the blur. (This "-level" will make 50% become 0%, and 100% become 100%.)

Image
snibgo's IM pages: im.snibgo.com
Post Reply