gradients going wrong

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?".
davidb2002
Posts: 37
Joined: 2008-09-01T08:31:26-07:00

gradients going wrong

Post by davidb2002 » 2008-09-01T08:43:24-07:00

Not sure why but for some reason My gradients for some hex doesnt work. See examples.

This works:
/usr/local/convert -size 10x100 gradient:"#CCCCCC"-"#CCCCCCFF" image.png

this doesnt:
/usr/local/convert -size 10x100 gradient:"#FF0080"-"#FF0080FF" image.png


Anyone know any idea why its not working. It did at one point.

User avatar
fmw42
Posts: 25664
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: gradients going wrong

Post by fmw42 » 2008-09-01T10:43:02-07:00

As far as I can tll both are working as you specified (IM 6.4.3-6 Q16). The two colors in each of your examples are identical. That is, #cccccc is the same as #ccccccff. In the first color there is no alpha channel so that is equivalent to opaque. In the second you have an alpha channel, but ff means opaque. Thus you have a gradient from opaque gray to opaque gray and thus a constant gray result - no gradient. In the second case, it is the same. Both colors are the same and so your gradient results in an opaque constant color. (I might have thought the alpha channel would turn on, but the verbose info shows no alpha).

See http://imagemagick.org/script/color.php

for more on colors.

What result were you looking for?

davidb2002
Posts: 37
Joined: 2008-09-01T08:31:26-07:00

Re: gradients going wrong

Post by davidb2002 » 2008-09-02T01:17:34-07:00

Our problem is that the image doesn't create at all. We inetned for it to be the same colors

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

Re: gradients going wrong

Post by anthony » 2008-09-02T21:29:33-07:00

The image should be created but if you want a solid color image, use xc: instead.

Code: Select all

   /usr/local/convert -size 10x100 xc:"#CCCCCC" image.png
See
http://www.imagemagick.org/Usage/canvas/
for details.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

davidb2002
Posts: 37
Joined: 2008-09-01T08:31:26-07:00

Re: gradients going wrong

Post by davidb2002 » 2008-09-03T01:24:54-07:00

Tried, that, looks like my problem is that im using 6.2 and it doesn't work with some hex. Upgrading is not an option (i am told by our server people). Anyone know a good way to do this in 6.2 ?

Works in 6.3 but not 6.2

/usr/local/convert -size 10x100 xc:"#FF0080" image.png

User avatar
fmw42
Posts: 25664
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: gradients going wrong

Post by fmw42 » 2008-09-03T11:40:59-07:00

davidb2002 wrote:Tried, that, looks like my problem is that im using 6.2 and it doesn't work with some hex. Upgrading is not an option (i am told by our server people). Anyone know a good way to do this in 6.2 ?

Works in 6.3 but not 6.2

/usr/local/convert -size 10x100 xc:"#FF0080" image.png
Have you tried changing #FF0080 to rgb(255,0,128). You will still need to use xc:"rgb(255,0,128)"

You can use IM to do the convert:
convert -size 1x1 xc:"#ff0080" -format "rgb(%[fx:floor(255*r)],%[fx:floor(255*g)],%[fx:floor(255*b)])" info:
returns rgb(255,0,128)

Alternately, decompose the colors into ff=255, 00=0, 80=128, then make three grayscale image using
convert -size 10x100 xc:white white.png
convert -size 10x100 xc:black black.png
convert -size 10x100 xc:gray128 gray.png

Then merge them back into an RGB image:
convert white.png black.png gray.png -combine rgb.png

In one step this is:
convert \( -size 10x100 xc:white \) \( size 10x100 xc:black \) \( size 10x100 xc:gray128 \) -combine rgb.png

davidb2002
Posts: 37
Joined: 2008-09-01T08:31:26-07:00

Re: gradients going wrong

Post by davidb2002 » 2008-09-04T01:37:37-07:00

convert -size 1x1 xc:"#ff0080" -format "rgb(%[fx:floor(255*r)],%[fx:floor(255*g)],%[fx:floor(255*b)])" info:
returns rgb(255,0,128)
tried that and it doesn't work for some still. In regards to the decompose. Is there a way to get imagemagik to decompose and convert the the correct names itself so I can do that automated?

Again, need something that works in 6.2

User avatar
fmw42
Posts: 25664
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: gradients going wrong

Post by fmw42 » 2008-09-04T10:49:58-07:00

davidb2002 wrote:
convert -size 1x1 xc:"#ff0080" -format "rgb(%[fx:floor(255*r)],%[fx:floor(255*g)],%[fx:floor(255*b)])" info:
returns rgb(255,0,128)
tried that and it doesn't work for some still. In regards to the decompose. Is there a way to get imagemagik to decompose and convert the the correct names itself so I can do that automated?

Again, need something that works in 6.2

Explain further. How can it work for some hex values and not for others? Give me an example that does not work.

If this is true, then you likely have a bad install.


You can try adding -depth 8
convert -size 1x1 xc:"#ff0080" -depth 8 -format "rgb(%[fx:floor(255*r)],%[fx:floor(255*g)],%[fx:floor(255*b)])" info:

You can also use:
convert -size 1x1 xc:"#ff0080" -depth 8 txt:

which returns
# ImageMagick pixel enumeration: 1,1,255,rgb
0,0: (255, 0,128) #FF0080 rgb(255,0,128)

or

color="#ff0080"
convert -size 1x1 xc:$color -depth 8 txt: | \
sed -n 's/^.*: ([ ]*\([0-9]*\),[ ]*\([0-9]*\),[ ]*\([0-9]*\)).*$/\1,\2,\3/p'

returns 255,0,128

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

Re: gradients going wrong

Post by anthony » 2008-09-04T17:52:20-07:00

I think we need to know more about you environment.

Are you a DOS used. runing from PHP script, or some UNIX shell
(what shell?)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

davidb2002
Posts: 37
Joined: 2008-09-01T08:31:26-07:00

Re: gradients going wrong

Post by davidb2002 » 2008-09-05T01:03:03-07:00

Linux version 2.6.18-53.1.21.el5 (mockbuild@builder10.centos.org) (gcc version 4.1.2 20070626 (Red Hat 4.1.2-14)) #1 SMP Tue May 20 09:35:07 EDT 2008

Imagemagik 6.2 (yum installed) for centos

Running shell cmd from PHP (not the PHP class)

User avatar
fmw42
Posts: 25664
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: gradients going wrong

Post by fmw42 » 2008-09-05T09:49:51-07:00

post an example of your php script that does not work. there are some very good php users, such as Bonzo, who might be able to help to see if there is some error.

Have you considered possibly an environment difference on your PHP setup between your servers.

davidb2002
Posts: 37
Joined: 2008-09-01T08:31:26-07:00

Re: gradients going wrong

Post by davidb2002 » 2008-09-08T01:49:05-07:00

[php]
<?php
$time_php = time();
$userfilename_final = $_SESSION[user_id]."_".$time_php.".jpg";

$userfilename = $_SESSION[user_id]."_".$time_php.".png";
$userfilename2 = $_SESSION[user_id]."_".$time_php."2.png";
$userfilename3 = $_SESSION[user_id]."_".$time_php."3.png";
$image = $_POST[award_shape];

$image = "award_".$image.".png";
$image_location_file_final = $userawardsdir .'temp/'.$userfilename_final;
$image_location_file = $userawardsdir .'temp/'.$userfilename;
$image_location_file2 = $userawardsdir .'temp/'.$userfilename2;
$image_location_file3 = $userawardsdir .'temp/'.$userfilename3;
$gradient = $userawardsdir .'default-components/gradients/gradient_temp.png';

//copy the image
$cmd = "/bin/cp " . $userawardsdir.'default-components/' . $image . " " . $image_location_file;
//echo $cmd;
exec($cmd);



$scheme_choice = $_POST[scheme];
$scheme_choice = explode('|',$scheme_choice);

$shape_colour = "#".$scheme_choice[1];
$background_colour = "#".$scheme_choice[0];
$text_on = $_POST[text_on];
$text_colour = "#".$scheme_choice[2];



$cmd = IMAGEMAGIKDIR.' -size 60x52 plasma:fractal -virtual-pixel edge -blur 0x5
-shade 140x45 -normalize
-size 1x100 xc:black -size 9x100 gradient:
+append '. $image_location_file;

# GET THE RGB VALUE OF THE HEX
$cmd = IMAGEMAGIKDIR.' -size 1x1 xc:"'.$shape_colour.'" -format "rgb(%[fx:floor(255*r)],%[fx:floor(255*g)],%[fx:floor(255*b)])" info:';
$rgb = exec($cmd);

$cmd = IMAGEMAGIKDIR.' -size 10x100 xc:"'.$rgb.'" '.$gradient;
#$cmd = IMAGEMAGIKDIR.' -size 10x100 xc:"'.$shape_colour.'" '.$gradient;
#$cmd = IMAGEMAGIKDIR.' -size 10x100 -opaque '.$shape_colour.' '.$gradient;
#echo '<!-- '.$cmd.'-->';
exec($cmd);
$cmd = IMAGEMAGIKDIR.' '.$image_location_file.' '.$gradient.' -fx \'v.p{0,u*v.h}\' '.$image_location_file2;
exec($cmd);




$cmd = IMAGEMAGIKDIR.' -size 60x52 xc:"'.$background_colour.'" -draw "image over 0,0 0,0 \''.$image_location_file2.'\'" '. $image_location_file3;
exec($cmd);

//so we have the image in image_locations 3
//destroy the others

unlink($image_location_file);
unlink($image_location_file2);

$cmd = IMAGEMAGIKDIR." ".$image_location_file3." -flatten ". $image_location_file_final;
exec($cmd);
unlink($image_location_file3);
?>
[/php]

davidb2002
Posts: 37
Joined: 2008-09-01T08:31:26-07:00

Re: gradients going wrong

Post by davidb2002 » 2008-09-17T01:47:03-07:00

Anyone want to have a stab at it? It appears to be a problem with the version of imagemagick i have.

User avatar
fmw42
Posts: 25664
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: gradients going wrong

Post by fmw42 » 2008-09-17T10:24:55-07:00

Again the most basic thing to do is to create 3 images for r,g,b and then merge together.

decompose the colors into ff=255, 00=0, 80=128, then make three grayscale image using
convert -size 10x100 xc:white white.png
convert -size 10x100 xc:black black.png
convert -size 10x100 xc:gray128 gray.png

Then merge them back into an RGB image:
convert white.png black.png gray.png -combine rgb.png

davidb2002
Posts: 37
Joined: 2008-09-01T08:31:26-07:00

Re: gradients going wrong

Post by davidb2002 » 2008-09-18T05:35:37-07:00

fmw42 wrote:Again the most basic thing to do is to create 3 images for r,g,b and then merge together.

decompose the colors into ff=255, 00=0, 80=128, then make three grayscale image using
convert -size 10x100 xc:white white.png
convert -size 10x100 xc:black black.png
convert -size 10x100 xc:gray128 gray.png

Then merge them back into an RGB image:
convert white.png black.png gray.png -combine rgb.png
Forgive me as i'm not that great with image magic. How do you decompose the colors of the image?

David

Post Reply