wrap around text (360.

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?".
Post Reply
gborbonus
Posts: 33
Joined: 2014-07-01T06:53:30-07:00
Authentication code: 6789

wrap around text (360.

Post by gborbonus »

hi guys,

So, I have this image:
Image

I would like to be able to add text to the image. The text should wrap with the image itself(3d sort of stuff here).

I am trying to think of how I can make this happen.

theories I've been working on:

1) make 5 images, left, leftone, text, rightone, right , the text image will repeat in the center, one for each letter. (did not work came out with images being too short next to images too high).

2) make a bunch of slices thick enough for 1 letter. then fill each slice with a letter, angled to the right proportion. then combine again. This came out much better, but certain letters took up less space then others, and made the text look bad.



I'm having a hard time thinking of other ways of doing it.

I also need to be able to make multiple images with different text, this is so I can use javascript to generate a 360 view and as the angle changes, so does the text that's actually displayed.

anyone know of way to do this with imagemagick?
Thank you,
Greg Borbonus
*nix system administrator
http://linkedin.com/in/gregborbonus
Skype: greg.borbonus
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: wrap around text (360.

Post by snibgo »

I would write text on an image, then transform that to match. See my page on "cylinders" for the maths and Windows scripts. Fred also has a page with a bash script.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: wrap around text (360.

Post by fmw42 »

What IM version and platform. With my unix bash shell script or possibly snibgo's windows script, you create a text image on a transparent background. Then warp to the cylinder and then overlay onto your ring image. Not sure how well that would work. But see my example of putting an image on a coffee cup a the link below for my cylinder script.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: wrap around text (360.

Post by snibgo »

For example, Windows BAT script:

Code: Select all

convert ^
  -size 198x500 ^
  -background None -fill rgba(0,0,100%%,0.9) ^
  label:"Hello Cruel World" ^
  -trim ^
  hw.png

call %PICTBAT%plane2cyl hw.png 19.6

convert ^
  yellow_wristband.png ^
  -trim ^
  ( hw_p2c.png -trim +repage ) ^
  -geometry +21+32 ^
  -composite ^
  hw_wristband.png
I calculate the tilt angle at 19.6 degrees (ie the camera is pointing down at that angle).
Image
snibgo's IM pages: im.snibgo.com
gborbonus
Posts: 33
Joined: 2014-07-01T06:53:30-07:00
Authentication code: 6789

Re: wrap around text (360.

Post by gborbonus »

hey guys,

Snibgo, that looks PERFECT.

Where did you come up with the dimensions for the text image? Right now I'm using linux, so I'm attempting to figure out how to use freds cylinder script with your example.
Thank you,
Greg Borbonus
*nix system administrator
http://linkedin.com/in/gregborbonus
Skype: greg.borbonus
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: wrap around text (360.

Post by snibgo »

The height, 500, is simply plenty high enough. To be honest, I tweaked the width until it worked.

In theory: the band is 119 pixels wide. This is the diameter. We want to "unwrap" half the circumference. Circumference = pi * diameter, so half the circum is pi * 119/2 = 187. We want hw.png to be this width, but this is a trimmed version of the original size, so I tweaked "-size" until it worked. hw.png turns out to be 180 wide.

Perhaps my plane2cyl.bat script has a bug. (I wouldn't be surprised.) Or I shouldn't use the auto-fitting of "label:", because changing the size from 198 to 199 to 200, I get a massive difference in the width of hw.png, perhaps because the pointsize is quantised. The best method is probably to create an over-size text image, then resize to the exact dimensions required. Let's try that:

Code: Select all

convert ^
  -size 400x1000 ^
  -background None -fill rgba(0,0,100%%,0.9) ^
  label:"Hello Cruel World" ^
  -trim +repage ^
  -resize "186x14^!" ^
  hw.png
Yes, this works fine. 186 looks better than 187.

The vertical distance from the top of the back to the top of the front is 40 pixels. Thus the camera points down by asin(40/119) = 19.6 degrees. I think this is Fred's "-p pitch" parameter.

My script uses parallel projection, not perspective projection. I think Fred's can do perspective, or at least simulate it, with "-e".
snibgo's IM pages: im.snibgo.com
gborbonus
Posts: 33
Joined: 2014-07-01T06:53:30-07:00
Authentication code: 6789

Re: wrap around text (360.

Post by gborbonus »

ok, looks good now.

I was able to make the text dynamic with the image. Everything is looking good now.

Just one question, mainly for fred.

Anyway to make the cylinderize script ouput a series of images(sprite to be made)?

Thanks
Thank you,
Greg Borbonus
*nix system administrator
http://linkedin.com/in/gregborbonus
Skype: greg.borbonus
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: wrap around text (360.

Post by fmw42 »

gborbonus wrote:ok, looks good now.

Just one question, mainly for fred.

Anyway to make the cylinderize script ouput a series of images(sprite to be made)?

Thanks

I am not sure what you mean by a sprite or series of images. If you mean an animation, then you would need to write a script to loop my cylinderize with different rotation arguments as I did on my example page, so that the image seems to rotate. You have to save each frame and combine into a gif animation or mpeg movie. If a gif animation, then the script can combine the frames in each loop increment by using IM miff format, then write the miff to gif at the end.

Please explain what you are trying to do.
gborbonus
Posts: 33
Joined: 2014-07-01T06:53:30-07:00
Authentication code: 6789

Re: wrap around text (360.

Post by gborbonus »

hi Fred,


Your first example is what I was attempting to do. Loop through and generate images for each angle(10 deg incr). combine those into a sprite.
If I was to use your script to generate animation, I could then go through and split the image you made to also do the same thing.

The reason I'm asking how to do it like this is that the loop took over 30 seconds to generate 36 images of 10 deg increments. This is far too long for my needs. I'm attempting to see how I can speed it up.
Thank you,
Greg Borbonus
*nix system administrator
http://linkedin.com/in/gregborbonus
Skype: greg.borbonus
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: wrap around text (360.

Post by fmw42 »

If I did a loop internally, it would not speed things up. It would require a substantial rewrite to make it faster. Perhaps user snibgo's code would be faster. It seems to be simpler than mine.

One other suggestion would be to resize your images closer to the output size before running cylinderize on them. That may save time.

The way you might approach it is to compute the distortion maps once and save them. The script can be edited to always output the distortion maps. Then use -roll +X+0 on the input image for each angle you want and then apply the distortion maps to each rolled image to create each frame of the output image. You can cut out the code for applying the distortion maps and put that into a loop, once you find the correct arguments and create the corresponding distortion maps.

Fred
gborbonus
Posts: 33
Joined: 2014-07-01T06:53:30-07:00
Authentication code: 6789

Re: wrap around text (360.

Post by gborbonus »

That would be an awesome feature of your script, to output the frames by degrees.

Just saying.

I'll attempt to do just that.

Thanks
Thank you,
Greg Borbonus
*nix system administrator
http://linkedin.com/in/gregborbonus
Skype: greg.borbonus
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: wrap around text (360.

Post by fmw42 »

gborbonus wrote:That would be an awesome feature of your script, to output the frames by degrees.

Just saying.

I'll attempt to do just that.

Thanks

It would have to be a different script, that would get the distortion maps from the current script and use them to apply for each angle. I do not have time right now to build that. Sorry.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: wrap around text (360.

Post by fmw42 »

I have modified my cylinderize script with the following changes:

1) New argument -r rotation to allow rotation of the output image before overlaying on the background image
2) New argument -E to allow the displacement map to be exported and special arguments listed to the terminal so that both can be used with my new script, cylinderwarp.

I have created a new script, cylinderwarp, to use the displacement map and arguments exported from cylinderize so that resulting images can be created more efficiently (speed up of about 4x) when the image sizes and all arguments do not change, except for the cylinder rotation angle (argument -a from cylinderize). This permits reuse of the displacement map and arguments without needing to regenerate the displacement map each time as in cylinderize. One example use of cylinder warp would be to generate a rotating animation. A set of commands is show to do just that along with an example.
Post Reply