Page 1 of 2

unexpected result of image flattening - doubling the width..

Posted: 2009-05-22T00:37:46-07:00
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

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

Posted: 2009-05-22T04:02:50-07:00
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.

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

Posted: 2009-05-22T09:57:39-07:00
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.

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

Posted: 2009-05-22T11:12:25-07:00
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..

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

Posted: 2009-05-22T11:18:41-07:00
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

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

Posted: 2009-05-22T18:07:57-07:00
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.

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

Posted: 2009-05-22T18:09:04-07:00
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)

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

Posted: 2009-05-22T19:06:16-07:00
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.

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

Posted: 2009-05-22T19:14:17-07:00
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 ?

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

Posted: 2009-05-22T19:35:32-07:00
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

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

Posted: 2009-05-22T19:43:16-07:00
by fmw42
you need to send to 2>&1

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

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

Posted: 2009-05-22T20:08:32-07:00
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.

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

Posted: 2009-05-22T20:10:27-07:00
by tobycarr
CORRECTION - i mean it writes that to the txt file NOT the image file

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

Posted: 2009-05-22T20:21:46-07:00
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

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

Posted: 2009-05-22T20:36:13-07:00
by tobycarr
Thanks Fred, that got it to at least echo.