After posting my latest pie chart image, it occurred to me that it would be pretty cool if the text flowed around the edge of the pie chart image rather than around a rectangle. This is not something that can be done simply with HTML / CSS, but it can be done by breaking the images up in to horizontal slices so that they extend only to the edge of the image, rather than to the absolute border.

Screenshot

If I googled for it, I suspect I could find tools to do this for me -- but where is the fun in that? Instead, I wrote a Python script that uses the Python Image Library to scan an image and output HTML that will allow text to wrap smoothing around the image. No additional images are produced, because the 'slicing' is done with CSS to select the part of the original image that is seen.

Here is the script: wrapimg.zip, and some examples of how to use it:

python wrapimg.py -o left.html sliceofpie.png python wrapimg.py -o right.html -d right sliceofpie.png

These two lines produced left.html and right.html.

The code is completely free, do what you will with it!

Update: I wanted to display an example in this blog-post, but Wordpress insists on re-writing my code and ruining the effect! :-( I should find a blogging system that is more techy-friendly!
This blog post was posted to It's All Geek to Me on Sunday August 3rd, 2008 at 4:59PM
 

5 Responses to "Image wrapping script"

  • August 3rd, 2008, 6:10 p.m.

    Hey Will,
    I can't download the code :(
    Here is the message by the server : error 403 Forbidden (Directory index forbidden by rule: wrapimg/)

  • August 3rd, 2008, 6:29 p.m.

    Sorry about that, give it a try now...

  • August 3rd, 2008, 8:45 p.m.

    Hi Will,

    You blog entry reminded me of something I saw a while ago and I was able to dig up the URL: http://www.ideashower.com/ideas/active/css-text-wrapper/. I think it does something similar.

    Anyway, I though you might find it interesting.

    Enjoy! :)

  • August 3rd, 2008, 8:58 p.m.

    This is great. I can't wait to find an excuse to use it.

  • August 4th, 2008, 5:01 p.m.

    Pretty neat. Perhaps you'd consider making it into a web utility on Utility Mill. It should mostly be a cut and paste job to get it running there.

Leave a Comment

You can use bbcode in the comment: e.g. [b]This is bold[/b], [url]http://www.willmcgugan.com[/url], [code python]import this[/code]
Preview Posting...
Previewing comment, please wait a moment...

My Tweets

Will McGugan

My name is Will McGugan. I am an unabashed geek, an author, a hacker and a Python expert – amongst other things!

Search for Posts
Possibly related posts
Tags
 
Popular Tags
 
Archives
2010
 
Recent Comments
Hi Will, I know that my college has spent thousands building a dreadful system called Portal that is incredibly weighty ...
This is very true, i believe that people need to be able to use a domain if they register it, ...
Hehe Thats a good tatoo idea ;) Have a nice day Joel
- Joel Shapiro on Powered by Ubuntu
Weirdly enough i am a junior dev on an internship. I am @ work and i was way too bored/out ...
I love the idea of locidesktop, and even more the minimal UI. Hope you'll keep it up!
 
© 2008 Will McGugan.

A technoblog blog, design by Will McGugan