I wrote a simple thing to do a similar operation for photos that are in-line with text on my website; I wrote a little bit about it at <a href="http:&#x2F;&#x2F;haldean.org&#x2F;hooke" rel="nofollow">http:&#x2F;&#x2F;haldean.org&#x2F;hooke</a> if people are interested!