Gradient Effect

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

Re: Gradient Effect

Post by geeta »

Hello Fred,
Once again thanks for all your kind help.
I need your help once again
As in IM's help I tried the following command

/usr/local/bin/convert /home/customav/public_html/beta/texteffect/images/theflower.jpg -matte -virtual-pixel transparent -channel A -blur 0x8 -evaluate subtract 50% -evaluate multiply 2 /home/customav/public_html/beta/texteffect/images/image_semi_transparent.jpg

which ideally should give a semi trasnparent image but it doenot have any effect on the image
The resultant image is
http://beta.customavenue.com/texteffect ... parent.jpg
original image is
http://beta.customavenue.com/texteffect ... flower.jpg

I wonder why that is not working .... :o
Ref.:http://www.imagemagick.org/Usage/transform/#evaluate

Thanks in Advance,
Geeta
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Gradient Effect

Post by Bonzo »

Try saving as a png as jpg does not support transparency.
geeta

Re: Gradient Effect

Post by geeta »

Thanks a Lot it Worked :D
One more thing I wanted to ask is does all the text effects like wave, glow,shadow work for png?
I mean does all the above commands and effects support transparency?
geeta

Re: Gradient Effect

Post by geeta »

Hello Fred,
Can you do a me a favour?
Can you give me the Image Magick commands that you have used to have all those text effects(Outline Bulge Text,Outline Concave Text,Outline Concave-Bottom Text,Outline Pinch Text,Outline Pinch-Top Text,Outline Pinch-Bottom Text,Outline Wedge-Left Text) that you have uploaded on your site?

Thanks in advance
Geeta
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Gradient Effect

Post by fmw42 »

You can download the script and look at it. It is plain text. It has the IM commands in the text for each type of effect and for each type of style. The styles and effects are in two different sections, but can be located by conditionals (if this..then that) The script is fairly transparent as it just makes standard IM commands to do the work. The top part of the script has some code for trapping on user supplied parameters. So you can skip that. The next section contains parameters that need to be computed from the user supplied options which are then used later. The core IM commands for doing the effects are near the bottom. You will see conditionals to tell you which sections are for which effects. Look for the section where I do the outline style (there are two - one with background none and with background other than none). Then look for the sections for each effect.

If you have trouble with this, let me know and I will try to isolate them for you.

The script can be found at http://www.fmwconcepts.com/imagemagick/index.html

Fred
geeta

Re: Gradient Effect

Post by geeta »

Hello Fred,
Thanks for your help and prompt reply. Actually I am not very good at sh so I am finding it very difficult to understand the script.
Can you explain me 2-3 of them so that I will try to understand rest of them

Can you explain me the following...
hh2=`convert xc: -format "%[fx:$distort*$h2]" info:`
hh3=`convert xc: -format "%[fx:$height-$distort*$h2]" info:`
im_version=`convert -list configure | \
sed '/^LIB_VERSION_NUMBER /!d; s//,/; s/,/,0/g; s/,0*\([0-9][0-9]\)/\1/g'`
if [ "$im_version" -lt "06030507" ]
then
coords="0,0 $width,0 $width,$height 0,$height 0,0 $width,$hh2 $width,$hh3 0,$height"
else
coords="0,0 0,0 $width,0 $width,$hh2 $width,$height $width,$hh3 0,$height 0,$height"
fi



AND----------------------------------------------------------


elif [ "$effect" = "bulge" -o "$effect" = "pinch" -o "$effect" = "bulge-top" -o "$effect" = "bulge-bottom" -o "$effect" = "pinch-top" -o "$effect" = "pinch-bottom" ]
then
convert $tmp0 $vp -background $bc \
-monitor -fx \
"xd=(i-$xc); yd=(j-$yc); rd=hypot(xd,yd)/$sf; ys=(yd/($a+$b*rd))+$yc; $result" \
-background $bc -trim -bordercolor $bc -border $pad \
$tmp0
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Gradient Effect

Post by fmw42 »

hh2=`convert xc: -format "%[fx:$distort*$h2]" info:`
hh3=`convert xc: -format "%[fx:$height-$distort*$h2]" info:`
im_version=`convert -list configure | \
sed '/^LIB_VERSION_NUMBER /!d; s//,/; s/,/,0/g; s/,0*\([0-9][0-9]\)/\1/g'`
if [ "$im_version" -lt "06030507" ]
then
coords="0,0 $width,0 $width,$height 0,$height 0,0 $width,$hh2 $width,$hh3 0,$height"
else
coords="0,0 0,0 $width,0 $width,$hh2 $width,$height $width,$hh3 0,$height 0,$height"
fi
$ signifies the use of a variable holding the value.
h2 was calculated before to be simply the height of the predistorted image image divided by 2.
I split the image in two halves so that I can distort only the top or only the bottom if desired.
hh2 is a scaled version of h2 - scaled by the distortion desired ( I am using fx here as a calculator).
im_version is an extraction of the IM version being used as the perspective coordinates usage changed at IM version 6.3.5.7 (actually you have an old version of the script as I later found out that it really changed at 6.3.6.0 - so download the current version of the script). In older versions the coordinates needed to specified as "srcxy1 ... srcxy4 dstxy1 ... dstxy4". In the newer versions the scr and dst coordinates are alternating "srcxy1 dstxy1 ... srcxy4 dstxy4".
The if statement switches the order of the coordinates to be consistent with the IM version usage of the coordinates in -distort perspective.
I compute the coordinate ahead of time and use them later in the actual -distort perspective section.

AND----------------------------------------------------------

elif [ "$effect" = "bulge" -o "$effect" = "pinch" -o "$effect" = "bulge-top" -o "$effect" = "bulge-bottom" -o "$effect" = "pinch-top" -o "$effect" = "pinch-bottom" ]
then
convert $tmp0 $vp -background $bc \
-monitor -fx \
"xd=(i-$xc); yd=(j-$yc); rd=hypot(xd,yd)/$sf; ys=(yd/($a+$b*rd))+$yc; $result" \
-background $bc -trim -bordercolor $bc -border $pad \
$tmp0
This is part of the "effects" calculation and is the section for doing the bulge-like effects. It is selected by the elif statement as part of a greater if, elif, elif... fi conditional. This is kind of hard to explain as it is a complex mathematical statement, using -fx to do the mathematical computation and application of the warping.
$vp defines the -virtual-pixel option, namely, vp="-virtual-pixel background" if the background color bc is not none. If it bc=none then vp="-matte -channel RGBA -virtual-pixel transparent" in order to make the background transparent. There is an earlier place that sets this definition for vp. The -monitor just enables the terminal display of a progress monitor as -fx is slow.
xd=i-$xc and yd=j-$yc is just making the origin of the image coordinates at the center of the image (xc,yc);
rd=hypot(xd,yd) is a shortcut to sqrt(xd^2,yd^2) that converts to circular coordinates (symmetry); and $sf is a scale factor that is the average of the half width and half height.
ys=(yd/($a+$b*rd)) is the bulge-pinch distortion formula/equation, a and b are related to the user provided distort value. You will have to see the earlier section where those are defined as the definition depends upon whether it is a bulge or a pinch. It is something like a=1-distort and b=distort.
All of this leads up to the part of fx that does the calculation $result="u.p{i,ys}" which simply takes the pixel at the input coordinates (i,ys) and loads then into the outut image at coordinates (i,j). Note this is the formula for the full bulge or pinch. To do the top or bottom it is modified to distort the top/bottom and leave the opposite half unchanged.
After the -fx, I trim whatever border there is and then put a border back in of the desired size.

I hope this helps.

Fred
Post Reply