different results with the same command?

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
knedl2007

different results with the same command?

Post by knedl2007 »

Hi folks,

my Problem is as follows. I want to take a picture, cutout a selection and create this:

Image

Therefore I use this command:
convert ( input.jpg -crop 764x245+0+0 -resize 764x245! ) ( ( -size 764x105 xc:white ) ( input.jpg -crop 764x245+0+0 -resize 764x105! -flip -paint 1 ) ( userprofil_top_bg_mirror_mask.png ) -alpha on -composite ) -append test.jpg

I take the picture (first parantheses), crop it and resize it to the right width and height. (in this case, the cutout ist exactly as big as desired). Then I take a white canvas with 764x105, load the picture again, crop it again the same way and resize it to 764x105, flip it and put an effect onto it. I load a mask image and compose these three ingredients alltogether. At the end, both pictures in the image stack are appended vertically.

BUT: If i use another input image as the one used for the example above the reflection part is rendered not correctly:

Image

It seems to depend on the input image!
I tried a lot of things, but I did not came up with a solution that works so far. Could this be a bug in ImageMagick?
Or is there a bug in my command?

Thanks for your help,
knedl
knedl2007

Re: different results with the same command?

Post by knedl2007 »

I think I have found the bug:

if i insert this statement:

convert ( input4.jpg -crop 1536x489+0+917 -resize 764x245! ) ( ( -size 764x105 xc:white ) ( -size 2304x1712 input4.jpg -crop 1536x489+0+917 -resize 764x105! -flip -paint 1 ) ( userprofil_top_bg_mirror_mask.png ) -alpha on -composite ) -append test2.jpg

to say, I declare the size of the image before i load it the second time, it seems to work.

Despite of the fact, that the command works properly now, could anybody tell me WHY it is important to declare the size of the image the second time? The original image file is not touched, is it? I thought the second time I would load the "untouched" original image...

thx, knedl
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: different results with the same command?

Post by anthony »

JPEG image reading is effected by -size as a hint on how big you want the image.
returned image will be larger than that hint but smaller than the original.

To stop this turn of -size using +size before reading JPG.


however you read the image, resize, then repeat it again! WHY? -clone the
original image read in, no need to deal with -size then as you aren't reading the jpeg again.

Code: Select all

  convert input4.jpg -crop 1536x489+0+917 -resize 764x245! \
             \( -clone -flip -paint 1   -size 764x105 xc:white  +swap \
                userprofil_top_bg_mirror_mask.png  -matte -composite \) \
             -append  test2.jpg
I did the -clone before creating the white as you did a little extra processing on it
I then +swap those two images into the right order afterward.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply