Switch to full style
Post all Gimp scripts and script writing questions here
Post a reply

Warped text

Sat Jul 03, 2010 4:43 pm

This script was written more as a learning exercise and I'm dubious as to its general utility. However, the crowd here seems somewhat adventurous and exceedingly creative, so I figured I'd see if any of you might not like to experiment a little with it.


The script will warp text to fit inside a four-point "Bezier patch". The bezier patch is created with the Path Tool, by placing first the upper-left anchor point, then the upper-right, followed by the lower-right, and finally the lower-left. You will probably want to close the path after placing the fourth point so that you can see the left-side curve. Closing a path is accomplished by holding down the CTRL key while clicking on the path's first anchor point.

The path that describes the target region
bezpatch.png (15.07 KiB) Viewed 9763 times

Once your patch is created, you can run the script (found under "Filters->Distorts->Warp Text...") on any text layer and eventually, after a good deal of huffing and puffing by the script, a new path will be created which is the outline of the text warped to fit within the patch. Basically, you are left just as you would be after doing a "Text along Path" in the Text tool Options dialog -- you are left to your own devices as to stroking the path, selecting from it and filling, etc. The dialog offers the option to warp any path, not just text; but I leave that for extra credit (perhap warping warped text? :) ).

Text path after warping
SSwarp.png (26.73 KiB) Viewed 9763 times

The fit is by no means perfect (usually mappings to Bezier surfaces entail additional control points inside the "patch"), but it may be useful for some situations. There is a "Padding" control which can be helpful in making sure the warped path doesn't fall outside the Bezier patch region (which is an unfortunate side effect of the shortcuts I took in my mapping algorithm). There is also a "Quality" setting which can range from below "10" (where letters are barely recognizable) to "250"; I don't notice much improvement above "100" and I set the default to "60" as speed versus quality compromise.

Let me know if you can find a use for it, if you find bugs, or if you can think of ways to improve it (I am considering allowing for more than four control points at some point, but that would require some slightly more sophisticated math).

EDIT: This script has now been submitted to the GIMP Plug-in Registry.

Re: Warped text

Sat Jul 03, 2010 5:53 pm

This is a fun script. I tried it with some dingbat hearts and, of course, came up with warped hearts.

Here is some text I played with. As with the hearts, the text came out sideways and mirrored. I need to work more to see what is causing that.

The original text is black, the first text is the brownish gradient and is mirrored and on its side. The orange and black text is after I rotated and flipped the text path.

I like the script and will continue playing with it to see what I come up with. I thought of making the text an animated "pulsing" movement ... done by changing the shape of the path several times. That will come later after I figure out how to make it come out right-side up and not mirrored.

Very cool script, saulgoode. :bigthup I can see using it where you'd want an unusual text formation that can't be done using just text. Band banners where the script is fitted into a frame. Like some of the Grateful Dead Posters I've seen. Kind of on this order http://images.wolfgangsvault.com/images/catalog/detail/FD012-PO.jpg

Re: Warped text

Sat Jul 03, 2010 6:38 pm

I have updated the script to fix a mistake (that caused the lower curve to be less influential).

As far as the flipped and/or rotated result, that is usually caused by the envelope path's points being in the wrong sequence, though it is possible I have a bug in my code. If you can't figure out what's happening, perhaps you can send me a small example XCF which exhibits the anomaly. My address is my user name @ flashingtwelve.brickfilms.com

Re: Warped text

Sat Jul 03, 2010 6:49 pm

It could possibly be the sequence of the points. I'm a left-hander and even though I use my right hand for the mouse, it could be that the different direction is carried over to my mouse hand. I'll work with that and see if there's a difference with different directions.

Re: Warped text

Sat Jul 03, 2010 11:06 pm

It does make a difference where you start the path and which direction you make it.

Upper Left and go CW all comes out fine.
Upper Left and CCW, comes out sideways and mirrored
Upper Right, CW makes it sideways but not mirrored
Upper Right, CCW upright but mirrored.

I deleted the old script and installed the updated one. I also closed and restarted GIMP to make sure the newest script was in effect.

Path was made starting on the lower right and CCW.
Text Came out upside down, mirrored, and turning it 180° corrected it.

These were just for fun and I used the same path on both dingbats.


Re: Warped text

Sun Jul 04, 2010 10:00 am

The filter is not very happy with the bottom upward curve in the GIMP text in this one.


Re: Warped text

Sun Jul 04, 2010 10:50 am

Oregonian wrote:The filter is not very happy with the bottom upward curve in the GIMP text in this one.

I would suggest checking your side curves; that result can be caused if there is "zig" in one of the sides. If a horizontal line through one of the side curves intersects at more than one point, such as shown below, the result would match what you've shown.

Overlapping side curve
SSsidepath.png (413 Bytes) Viewed 9715 times

The "zig" may not even be visible when viewing the path; the overlapping points may lie directly over each other if the control handle for an anchor is located farther away than the other anchor.

If this is not the cause, perhaps you could export your path (available by right clicking on its thumbnail in the Paths Dialog) and provide me with the file (or provide an XCF containing your path).

Thanks for testing the script and providing feedback.

Re: Warped text

Sun Jul 04, 2010 10:52 am

I did save it as an xcf file thinking you may want to look at it. Here it is.

Re: Warped text

Sun Jul 04, 2010 11:12 am

Ahh, yes. Thanks.

The problem is indeed caused by the fact that the side curves have more than one X value for a given Y (though not exactly the "zig" I previously suggested).

If you can reposition your anchors to the bottom corners then you will not have that problem.
Repositioned anchors
SSmoved-anchors.png (1.05 KiB) Viewed 9709 times

As a general rule (unless one wants the distortion you obtained :) ), a control handle should always lie between its anchor and the adjacent anchor (either the next anchor in the path or the previous, depending on which control handle).

For example, in the above screenshot the control handle which happens to be closest to the lower-left anchor (the open circle) must not below the bottom-left anchor. Likewise, the other control handle shown must be to the right of the lower-left anchor.

Of course, rules can always be disregarded, if you are willing to accept the consequences.

Re: Warped text

Sun Jul 04, 2010 11:30 am

I opened up my faulty path xcf file so I could visually see what you were saying about it. Aha! Understand.

Fixed my path.

Post a reply