Background keeps black black black (-background blue)

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

Background keeps black black black (-background blue)

Post 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?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post 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)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post by magick »

We tried your command with ImageMagick 6.4.2-1, the current release, and it produced a blue background as expected.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
forumim

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

Post by forumim »

Thanks a lot!
I have Version 6.2.8 04.
So I will update and try again.
forumim

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

Post 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);
jbraegger

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

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
jbraegger

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

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
jbraegger

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

Post 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
lsteamgeo

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

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
lsteamgeo

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

Post 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.
Post Reply