unexpected result of image flattening - doubling the width..

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?".
tobycarr

unexpected result of image flattening - doubling the width..

Post by tobycarr »

Hi,
Sorry if it's obvious as I am a newb but why would the following code be outputting an image that is twice the width (x dimension) of the original?
I am expecting, and thought in my previous tests to be getting, a simple overlaying of the 2 overlay images onto the original background image without it changing in x or y dimensions:

Code: Select all

  convert   bg_image.png   -page +25+25 overlay_1.png   -page +25+50 overlay_2.png   -background transparent -flatten image_out.png  
Thanks for any help/clues
tobycarr

Re: unexpected result of image flattening - doubling the width..

Post by tobycarr »

Here are examples of the actual images used and a piece of example code -->
NOTE - bg image starts out as 240 x270

Image
Image

Code: Select all

 convert  bg_image.png   -page +25+25  overlay.png   -background transparent  -flatten  image_out.png 
resulting in this image of 480 x 270 -->

Image

NOTE: the image bg_image.png has itself been earlier created by IM.
NOTE: This only seems to happen where the bg image has been created by IM.

Is anyone able to analyse the bg image to see if the problem lies in its properties somehow.
I have opened in Photoshop and GraphicsConverter and it seems to be a kosher png file of 240 x 270.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: unexpected result of image flattening - doubling the width..

Post by fmw42 »

Your bg_image.png probably has a virtual canvas (perhaps from using -crop). How did you create it in IM. Try adding +repage at the end of the command line that creates it or

convert \( bg_image.png +repage \) -page +25+25 overlay.png -background transparent -flatten image_out.png

Yes, this last does work.
tobycarr

Re: unexpected result of image flattening - doubling the width..

Post by tobycarr »

Great! Thank you very much - works nicely. SO does that mean a png file created with IM carries some IM-based info like virtual canvas dimensions, or is that standard for pngs? Excuse my ignorance..
tobycarr

Re: unexpected result of image flattening - doubling the width..

Post by tobycarr »

Fred, while I've potentially got your ear here - thanks for the great stuff on your site ..
quick question .. I tried all the convert -list commands at the bottom of your tidbits page and all were fine except for the "convert -list" by itself used to list functions.. for that one I got nothing - is there an alternate command for that?
ta
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: unexpected result of image flattening - doubling the width..

Post by fmw42 »

tobycarr wrote:Great! Thank you very much - works nicely. SO does that mean a png file created with IM carries some IM-based info like virtual canvas dimensions, or is that standard for pngs? Excuse my ignorance..
Yes as best as I understand, but I will defer to the IM folks for a better explanation. PNG can carry virtual canvas information, but usually does not or at least it is the same as the image size. It depends upon the IM functions you used to create the image. Crop is one that will keep virtual canvas information in the file and thus needs +repage to set it to the image size.

How did you create your original file bg_image.png? You never said. Thus I could only speculate why it had a virtual canvas.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: unexpected result of image flattening - doubling the width..

Post by fmw42 »

tobycarr wrote:Fred, while I've potentially got your ear here - thanks for the great stuff on your site ..
quick question .. I tried all the convert -list commands at the bottom of your tidbits page and all were fine except for the "convert -list" by itself used to list functions.. for that one I got nothing - is there an alternate command for that?
ta
It still works for me on IM 6.5.2-7 Q16 Mac OSX Tiger:

convert -list
Version: ImageMagick 6.5.2-7 2009-05-20 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC

Usage: convert [options ...] file [ [options ...] file ...] [options ...] file

Image Settings:
-adjoin join images into a single multi-image file
-affine matrix affine transform matrix
-alpha option activate, deactivate, reset, or set the alpha channel
-antialias remove pixel-aliasing
-authenticate password
decipher image with this password
-attenuate value lessen (or intensify) when adding noise to an image
-background color background color
-bias value add bias when convolving an image
-black-point-compensation
use black point compensation
-blue-primary point chromaticity blue primary point
-bordercolor color border color
-caption string assign a caption to an image
-channel type apply option to select image channels
-colors value preferred number of colors in the image
-colorspace type alternate image colorspace
-comment string annotate image with comment
-compose operator set image composite operator
...

(very long list produced)
tobycarr

Re: unexpected result of image flattening - doubling the width..

Post by tobycarr »

fmw42 wrote: How did you create your original file bg_image.png? You never said. Thus I could only speculate why it had a virtual canvas.
sorry - yes - it was crop image then append back on at different xy. you got it.
tobycarr

Re: unexpected result of image flattening - doubling the width..

Post by tobycarr »

fmw42 wrote:
It still works for me on IM 6.5.2-7 Q16 Mac OSX Tiger:
..mmmm.. not sure why not working for me .. IM 6.5.0 Mac OS X 10.5.7 Leopard ..
should I be using IM 6.5.2-7 ?
tobycarr

Re: unexpected result of image flattening - doubling the width..

Post by tobycarr »

Code: Select all

$convert  = " (convert -list -verbose info:) > func_list.txt ";
exec($convert);
I am using this code as php shell exec - which works for all the other list examples,
perhaps file is so large it is breaching some file max for verbose - shouldn't be too large for my php which is set at very high max's?? and sending nothing..
txt file is being created but is blank..
as I say all other list examples from your page work e.g.

Code: Select all

$convert  = " (convert -list gravity -verbose info:) > grav_list.txt ";
exec($convert);
gives me a text file with this in it -->
None
Center
East
Forget
NorthEast
North
NorthWest
SouthEast
South
SouthWest
West
Static
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: unexpected result of image flattening - doubling the width..

Post by fmw42 »

you need to send to 2>&1

see some comments on doing that in PHP at viewtopic.php?f=1&t=13725
tobycarr

Re: unexpected result of image flattening - doubling the width..

Post by tobycarr »

When I include 2>&1

as in
$convert = " (convert -list -verbose info:) 2>&1 func_list.txt ";
exec($convert);
..it writes this to the image file -->

convert: unrecognized list type `-verbose' @ convert.c/ConvertImageCommand/1724.
tobycarr

Re: unexpected result of image flattening - doubling the width..

Post by tobycarr »

CORRECTION - i mean it writes that to the txt file NOT the image file
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: unexpected result of image flattening - doubling the width..

Post by fmw42 »

I am not a PHP expert, but following what was in the forum article try

$output = shell_exec("/FULL PATH TO/convert -list 2>&1");
echo "<pre>$output</pre>";

path to convert is often /usr/local/bin
tobycarr

Re: unexpected result of image flattening - doubling the width..

Post by tobycarr »

Thanks Fred, that got it to at least echo.
Post Reply