Page 1 of 2

Background keeps black black black (-background blue)

Posted: 2008-07-09T07:06:21-07:00
by forumim
When I extent an image,
I would like this extension in blue color.

Instead it is always black.

Code: Select all

exec("convert input.jpg -background blue -extent 1000x900 output.jpg", $arr, $err);
I have the same effect with -fill.
Any idea?

Re: Background keeps black black black (-background blue)

Posted: 2008-07-09T09:14:24-07:00
by Bonzo
What happens if you use a different colour to blue ?

Find what colour names are supported by Imagemagick with:

Code: Select all

<?php
echo "<pre>";
exec("convert -list color");
echo "</pre>";
?> 
Try using a hex or RGB colour:

Code: Select all

-background #0000FF
-background RGB(0,0,255)

Re: Background keeps black black black (-background blue)

Posted: 2008-07-09T09:57:11-07:00
by magick
We tried your command with ImageMagick 6.4.2-1, the current release, and it produced a blue background as expected.

Re: Background keeps black black black (-background blue)

Posted: 2008-07-09T18:11:31-07:00
by anthony
If it cam out black your IM version is older than v6.3.2 when the update to the -extent operator are added.
On the other hand it is newer than v6.2.4 which was when the operator was first added.

See IM examples, Extent for details, and version numbers
http://imagemagick.org/Usage/crop/#extent

Re: Background keeps black black black (-background blue)

Posted: 2008-07-10T00:42:25-07:00
by forumim
Thanks a lot!
I have Version 6.2.8 04.
So I will update and try again.

Re: Background keeps black black black (-background blue)

Posted: 2008-07-10T06:32:37-07:00
by forumim
It works! Problem solved.

In Version: 6.4.2

Code: Select all

exec("convert input.jpg -background blue -extent 1000x900 output.jpg", $arr, $err);

Re: Background keeps black black black (-background blue)

Posted: 2009-06-11T12:40:58-07:00
by jbraegger
I am running into this problem as well, with 6.5.2

Code: Select all

curl -sO http://www.classyandcool.com/files/movinggif.gif
convert movinggif.gif -background white movinggif.jpg
mv movinggif-0.jpg movinggif.jpg
rm movinggif-*.jpg
When I add -extent (which I don't want to do), the background is white as expected... only without using the -extent option is it appearing black.

Re: Background keeps black black black (-background blue)

Posted: 2009-06-11T13:40:48-07:00
by fmw42
I believe that -background is setting not an operator. So by itself it will not do anything. It needs a corresponding operator to do something (like -extent, etc).

Post your image and tell us what you want to do with it.

Re: Background keeps black black black (-background blue)

Posted: 2009-06-11T15:44:59-07:00
by jbraegger
The image is actually in the previous post, but I guess it's hidden in the commands. Here's the cute little guy:

Image

Basically what I want to do is convert any image (whether it be tif, jpeg) to a 'standard' jpeg, while maintaining size and color. For animated gifs, such at the image I provided, I want to only use the first frame.
I believe that -background is setting not an operator. So by itself it will not do anything. It needs a corresponding operator to do something (like -extent, etc).


Isn't 'convert' an operation in and of itself? Is there something I can "do" that really doesn't do anything?

I'm actually using Image::Magick (perl wrapper) in my code, I just used the 'convert' utility to more easily produce the problem I'm seeing... but I'm using relatively the same options in perl.

Re: Background keeps black black black (-background blue)

Posted: 2009-06-11T16:44:18-07:00
by anthony
GIF and TIF images can contain transparency. JPEG images can not contain transparency, so whatever color is being hidden by the transparency will suddenly appear.

In GIF images this is the color modified by the '-transparent-color' setting
See GIF Transparency Color
http://www.imagemagick.org/Usage/formats/#gif_trans

For TIF and PNG that color could be anything.

If not defined often that color happens to be a mathematical zero color.... Black.

The only fix is to some how 'flatten' the image onto some opaque color so as to remove any transparency. This can be done using any of the operators -flatten, -mosaic, -border, -frame, -extent though the color source used varies from operator to operator.

All of the above actually generates a background canvas image (containing the same meta-data as the original image), then uses the default 'over' Alpha Composition (-composite) to overlay the image onto that background canvas. The differences in the operators is WHY that operator does this, typically as part of some larger operation typically to change the size of the image (add border space or compose-crop the image.

Re: Background keeps black black black (-background blue)

Posted: 2009-06-11T18:16:26-07:00
by fmw42
Isn't 'convert' an operation in and of itself?
What I meant was you need some "option" that is an "action" or "operator" option to apply the "setting" option used by the convert "command". Action operators such as -extent, -border, -flatten, etc

See Anthony's page http://www.imagemagick.org/Usage/reference.html to distinguish operators from settings.

Re: Background keeps black black black (-background blue)

Posted: 2009-06-13T10:38:28-07:00
by jbraegger
That works great, thanks a bunch. What I ended up doing was getting the first frame of the animated gif, and flattening the image... worked beautifully. I appreciate the explanation, it helped clarify a lot.

-Josh

Re: Background keeps black black black (-background blue)

Posted: 2010-07-08T05:30:46-07:00
by lsteamgeo
Hi,

I have a problem. I feel like I have two versions of ImageMagick which runs on the server.

When I do a "convert --version" with SSH i've the following response:

Code: Select all

Version: ImageMagick 6.6.3-0 Q16 http://www.imagemagick.org 2010-07-08
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP
When I do a "convert --version" with an exec() in php I have the following response:

Code: Select all

Version:ImageMagick 6.2.8 04/17/08 Q16 file: / usr/share/ImageMagick-6.2.8/doc/index.html
Copyright: Copyright (C) 1999-2006 ImageMagick Studio LLC
I resize the images with an exec in PHP so I have the black background.

How can I ask PHP to use the latest version of ImageMagick is installed.

I'm on CentOS with cpanel.

Thank you.

Re: Background keeps black black black (-background blue)

Posted: 2010-07-08T09:23:04-07:00
by fmw42
just provide the full path to the IM version you want with the convert command in your PHP exec command

/fullpathtoIM/convert ....


often one is at /usr/local/bin and the other at /usr/bin

try

<?php
exec("/usr/local/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>

And see what version is returned. Then change it to /usr/bin/convert

If neither of these give you the version you want, then ask your ISP where they are installed.

If this does not work, then one of the PHP experts may be able to offer a better way to find the path to IM

Re: Background keeps black black black (-background blue)

Posted: 2010-07-08T10:53:00-07:00
by lsteamgeo
Thanks you for your help,

All code i've tested with exec() return the old version

Code: Select all

exec("convert -version"); return Version: ImageMagick 6.2.8

Code: Select all

exec("/usr/bin/convert -version");  return Version: ImageMagick 6.2.8

Code: Select all

exec("/usr/local/bin/convert -version");  return Version: ImageMagick 6.2.8
The new version is return with convert in SSH.

Code: Select all

convert --version      return Version: ImageMagick 6.6.3-0
How i can find the new installation of ImageMagick and how i can change sur actually "convert" by the new version?

Sorry for my bad English,

Thanks.