Creating Text WordArt Effects

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

Re: Creating Text WordArt Effects

Post by fmw42 »

He uses a cartesian to polar transformation to do the "arc" distort.

By the way, to do something like the barrel and pincushion distortion with IM commands see the implode function. I think that may do what you want. Implode with positive value is like pincushion and implode with negative value is like barrel.

http://www.imagemagick.org/Usage/distorts/#implode
TheBuzzer

Re: Creating Text WordArt Effects

Post by TheBuzzer »

what u mean by that?
He uses a cartesian to polar transformation to do the "arc" distort.
TheBuzzer

Re: Creating Text WordArt Effects

Post by TheBuzzer »

also inplode does it to all sides.

any way to make it limited to doing just one side
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Creating Text WordArt Effects

Post by fmw42 »

Cartesian to polar is the type of transformation. It uses equations such as

r=sqrt(x^2 + y^2)
angle=atan2(y,x)

and

x=r*cos(angle)
y=r*sin(angle)


With regard to -implode, I don't know of any way to make it do it to just one dimension without doing a custom distortion mapping or writing equations such as I did in pincushion.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Creating Text WordArt Effects

Post by fmw42 »

I have simplified my script for doing barrel and pincushion distortion only in the vertical dimension for you. It uses no Unix, only IM commands to get and compute parameters.

Here is an example:

input text image: http://www.fmwconcepts.com/misc_tests/T ... edtext.jpg
barrel distorted: http://www.fmwconcepts.com/misc_tests/T ... l_d0p5.jpg
pincushion distorted: http://www.fmwconcepts.com/misc_tests/T ... _dm0p5.jpg

the processing took only about 4 seconds on this example.


Here is the code. You should be able to take it and modify it for you application, now. The only parameter apart from the input and output images is a distortion amount, d, that ranges from 0 to +1 for barrel distortion and 0 to -1 for pincushion distortion. A value of zero leaves the image unchanged. Small values are adequate (near zero). My example used d=.5 for barrel and d=-.5 for pincushion. Let me know how this works out for you, until Anthony can code this into IM.

#!/bin/bash

# Radial (Barrel/Pincushion) Distortion
# simple first order inverse polynomial in radius applied only to y dimension

# define input image name
infile="fredtext.png"

# input parameter - amount of distortion (smaller is less, larger is more, 0 is no change)
d=0.5 # d ranges from 0 to +1 for barrel and 0 to -1 for pincushion


# define automatic output image name (you can remove this section for your own naming)
inname=`echo "$infile" | sed -n 's/^\([^.]*\)[.][^.]*$/\1/ p'`
dd=`echo "$d" | tr "." "p"`
dd=`echo "$dd" | tr "-" "m"`
outfile="${inname}_pinbarrel_d$dd.jpg"
echo "outfile=$outfile"

# computed parameters (you need these)
a=`convert xc: -format "%[fx:1+$d]" info:`
b=`convert xc: -format "%[fx:-$d]" info:`
width=`identify -format %w $infile`
height=`identify -format %h $infile`
w2=`convert xc: -format "%[fx:$width/2]" info:`
h2=`convert xc: -format "%[fx:$height/2]" info:`
sf=`convert xc: -format "%[fx:($w2+$h2)/2]" info:`
xc=$w2
yc=$h2


# process image
convert -monitor $infile -fx \
"xd=(i-$xc); yd=(j-$yc); rd=hypot(xd,yd)/$sf; ys=(yd/($a+$b*rd))+$yc; u.p{i,ys}" \
$outfile

exit 0
TheBuzzer

Re: Creating Text WordArt Effects

Post by TheBuzzer »

thanks.

i also did a curve more similer to how the customink does it where the letters doesnt curve just rotates along a path.

I did it a cheap way though where I made php program out a svg file with a textpath that is a curve and use the java svg to png converter because imagemagik cant do textpaths.

so i will try doing this wedge thing into another function tomorrow. and it would just be missing just 2 more effects.
TheBuzzer

Re: Creating Text WordArt Effects

Post by TheBuzzer »

well i still too sure about your script

the

# computed parameters (you need these)
a=`convert xc: -format "%[fx:1+$d]" info:`
b=`convert xc: -format "%[fx:-$d]" info:`
width=`identify -format %w $infile`
height=`identify -format %h $infile`
w2=`convert xc: -format "%[fx:$width/2]" info:`
h2=`convert xc: -format "%[fx:$height/2]" info:`
sf=`convert xc: -format "%[fx:($w2+$h2)/2]" info:`
xc=$w2
yc=$h2


i don't really understand this part
your writing in a language I dont understand and I have no clue how it works in this part.


Not too sure how to rewrite this part to php to use.

Are they suppose to be seperate functions but than it doesnt look like those are functions and look like other commands.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Creating Text WordArt Effects

Post by fmw42 »

Each line computes a separate variable that is needed later by the script. d is the distortion amount provided by the user from input. The others are computed using IM option -format and some use -fx to do calculations. Look at

-format, -fx and -fx escapes

See

http://www.imagemagick.org/script/escape.php
http://www.imagemagick.org/script/fx.php
http://www.imagemagick.org/Usage/transform/#fx_escapes

You can probably do much of the calculations directly in PHP as it has its own math processor. The width and height you need to get from IM in any manner that PHP lets you do that.

In simple math terms:

a=1+d
b=-d
width=width of input image
height=height of input image
w2=width/2
h2=height/2
sf=(w2+h2)/2
xc=w2
yc=h2
TheBuzzer

Re: Creating Text WordArt Effects

Post by TheBuzzer »

well i just tried it but i see the pin cusion but yet i see my old text as background or something looks weird end result
TheBuzzer

Re: Creating Text WordArt Effects

Post by TheBuzzer »

it seems like it is something to do with saving as png.

if it save to jpg it looks fine.

is there a way to fix that?
TheBuzzer

Re: Creating Text WordArt Effects

Post by TheBuzzer »

this is still really slow to use on a windows machine the effect is right i guess i just have to wait till this functions are coded directly into image magik
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Creating Text WordArt Effects

Post by fmw42 »

I do not know why it should not work with either png or jpg unless you need to use transparency and then you need to use either gif or png. However, colors will not be preserved as well using jpg because it is a lossy compression format.

With regard to speed, unfortunately there is nothing that can be done to make it faster (other than coding it in an API such as PerlMagick or Magicwand for PHP) until Anthony can code the pinbarrel distort into a real IM function.

By the way, I just uploaded a bash script, texteffect, to my web page that does a lot of these effects. You can get the script and see all my examples at http://www.fmwconcepts.com/imagemagick/index.html
TheBuzzer

Re: Creating Text WordArt Effects

Post by TheBuzzer »

nice. how fast it runs though?

I am wondering does it run faster on linux compared to windows
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Creating Text WordArt Effects

Post by fmw42 »

Timing will depend on many factors - your processor, the length of the text and the effect. As I mentioned, some of these effects require -fx until Anthony can code them directly in IM. On my Mac 1.42 GHz processor some three-word text effects take only 1 second, but some that use -fx take 20 seconds. I have no idea how fast they are on other processors including PC/Windows.

They would run faster if they were coded in some API such as Perlmagick or MagicWand for PHP, but I only coded them in bash shell script.

By the way, I just now uploaded a new version that adds several other styles: bevel, antibevel, hardshadow and stamp. I also allowed it to use an input image that will tile the text with a pattern instead of just coloring it.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Creating Text WordArt Effects

Post by fmw42 »

I just uploaded a new version to fix some parameter trapping errors and add some new styles.

And another version has just been uploaded 4/7/08 to fix some documentation errors on the examples and to trap on the changed control point format for the perspective distort (wedge) before and after IM version 6.3.5.7

Fred
Post Reply