This command properly draws a 1 pixel x 100 pixel green to transparent gradient which is the echo'd to the screen.
exec ("convert -size 1x100 gradient:green-none ".$_SERVER['DOCUMENT_ROOT']."/temp/FAFAFA_trans2.png");
I have then increased it size and made it viewable. All that worked just fine.
echo "<img src='/temp/FAFAFA_trans2.png' width='100' height='500'>";
However, it's a 50/50 bleed of green and transparent meeting in the middle. I'm looking to have that transparency fade out much sooner. more like a 20/80 gradient. How can I create such an 'on the fly' gradient image weighting the strength of one color vs another.
I have created two simple gradients. Please have a look at this link: http://www.titeurl.com/imagick.
The first one was actually created using the code above ie;
However, I cannot find an example in the Imagemagick documentation showing how I might adjust the length of the green vs the transparent. So for instance, if I am creating a 100 pixel gradient of green and white, what if I wish for 20% to be green and 80% whilte or something like that.
Thanks.
Jay
2 Color Gradient - How to emphasize 30/70 distribution
-
- Posts: 2
- Joined: 2011-10-09T13:36:00-07:00
- Authentication code: 8675308
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: 2 Color Gradient - How to emphasize 30/70 distribution
To adjust the gradient you can use -evaluate and -function operators on the alpha channel.
I recommend using the power functions
Examples of this (applying to a black and white gradient without alpha channel limitation) is shown in
http://www.imagemagick.org/Usage/transf ... aluate_pow
Another alternative (also limiting to the alpha channel) is to use sigmoidal-contrast
http://www.imagemagick.org/Usage/color_mods/#sigmoidal
Just set the 'mid-point' to either 0% or 100% to produce similar power functions.
I recommend using the power functions
Examples of this (applying to a black and white gradient without alpha channel limitation) is shown in
http://www.imagemagick.org/Usage/transf ... aluate_pow
Another alternative (also limiting to the alpha channel) is to use sigmoidal-contrast
http://www.imagemagick.org/Usage/color_mods/#sigmoidal
Just set the 'mid-point' to either 0% or 100% to produce similar power functions.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: 2 Color Gradient - How to emphasize 30/70 distribution
Try this with varying offsets (-100 to +100). Zero gives the usual gradient. Not really sure it is doing what you want, but let us know.
lcolor=green
hcolor=white
width=256
height=10
offset=0
convert -size 1x1 xc:$lcolor xc:$hcolor +append -auto-level \
-filter triangle -resize ${width}x1! \
-virtual-pixel edge -fx "u.p{i-$offset*w/200,j}" -scale ${width}x${height}! \
${lcolor}_${hcolor}_grad_${offset}.gif
Or try this. Vary factor larger or smaller than 1. factor=1 is the usual gradient. Change it by tenths. (e.g 1.1 or 0.9 etc)
factor=1
lcolor=green
hcolor=white
width=256
height=10
convert -size ${width}x${height} xc: \( -size 1x1 xc:$lcolor xc:$hcolor +append \) \
-fx "v.p{i/($factor*w),j}" ${lcolor}_${hcolor}_grad_${factor}.gif
see
http://www.imagemagick.org/Usage/canvas ... nterpolate
lcolor=green
hcolor=white
width=256
height=10
offset=0
convert -size 1x1 xc:$lcolor xc:$hcolor +append -auto-level \
-filter triangle -resize ${width}x1! \
-virtual-pixel edge -fx "u.p{i-$offset*w/200,j}" -scale ${width}x${height}! \
${lcolor}_${hcolor}_grad_${offset}.gif
Or try this. Vary factor larger or smaller than 1. factor=1 is the usual gradient. Change it by tenths. (e.g 1.1 or 0.9 etc)
factor=1
lcolor=green
hcolor=white
width=256
height=10
convert -size ${width}x${height} xc: \( -size 1x1 xc:$lcolor xc:$hcolor +append \) \
-fx "v.p{i/($factor*w),j}" ${lcolor}_${hcolor}_grad_${factor}.gif
see
http://www.imagemagick.org/Usage/canvas ... nterpolate
-
- Posts: 2
- Joined: 2011-10-09T13:36:00-07:00
- Authentication code: 8675308
Re: 2 Color Gradient - How to emphasize 30/70 distribution
I am grateful for the replies and have tested all of them. I have determined that Anthony's post provides the most friendly and fast method of accomplishing the goal. The results of my testing can be seen here:
http://sta.compumatter.com/pages/test/
Thank you.
I do have one other issue perhaps and that is the light banding that is occuring. Does anyone have a thought on that one ?
Jay
http://sta.compumatter.com/pages/test/
Thank you.
I do have one other issue perhaps and that is the light banding that is occuring. Does anyone have a thought on that one ?
Jay
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: 2 Color Gradient - How to emphasize 30/70 distribution
Your test images don't show much green. And the command does not generate transparency.
GIF only handles Boolean (on/off) transparency only not graded transparency
The banding is probably due to color reduction, but also can be cause by saving intermediate image results to a lossy color format like GIF. Better to do all your processing in memory if posible then save at the end.
GIF only handles Boolean (on/off) transparency only not graded transparency
The banding is probably due to color reduction, but also can be cause by saving intermediate image results to a lossy color format like GIF. Better to do all your processing in memory if posible then save at the end.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/