I just published a small plugin for WordPress. I use it to dynamically resize and crop photos on this site.
WordPress resizes uploaded images to two different sizes. A thumbnail and a medium format. In most designs you would really like to control how an image is used on the page. Sometimes it will be a small cropped thumbnail, another time a bit bigger, or a nice medium format on the post pages themselves.
The wok-imager plugin enables this without you resizing the images for WordPress.
Tested with PHP 5.2 and WordPress 2.7 and 2.6.3. Many thanks to Tim Benniks for testing it with WordPress 2.7.
Short version:
cd wp-content/plugins/
svn checkout http://wp-wok-imager.googlecode.com/svn/trunk/ wok-imager
Go to the admin page of your site and install the plugin.
Just add an image element in your page:
<img src="/wp-content/uploads/file.jpg" width="100" height="100" filter="crop,gray" />
The wok-imager will scan your generated page upon serving, apply the width, height and filters to the image and change the tag into something like:
<img src="/wp-content/uploads/wok-imager/file.jpg/4ee630a60ec7feb605516ac5b98972d1.jpg" width="100" height="100" />
When you don’t supply the crop filter then the width and height are the maximum bounding rectangle of the image. The resulting image has either the given width or the given height but is never bigger than the given width and height. You can also supply just the width or the height to make the resized image unbounded in respectively the height or the width.
You can combine multiple filters by separating then with a comma. For example “crop,flip,gray”.
Examples:
crop center crop
cropcc center crop
croptl upper left corner
cropbr lower right corner
You can add your own imager plugins. There are two examples in the imager-plugin directory.
Works great on wordpress 2.7
Quite cool! I spent soo much time on resizing images for Shirtlog.com
What I thought would be cool (and slight on the copyright dark side) is have a plugin that reeds rss feeds, and resizes the images of that rss feed to exactly the size I want them. In that way I would be able to start meta blogging all kinds of stuff and make it look like it was actually me who did all the work (or I could even still be friendly and show the url where the posts are coming from)
I can imagine that this would be particular useful for subjects where images are more important than text: photography, gadgets, t-shirts, architecture, interior, design, art etc..
Thanks, ill play with it a bit
Hei Sjors,
That sounds like a good idea. Maybe we can make it so that if the source of the image is a http uri we always download the image and start resizing it to the sizes supplied in the image element.
I will file a change request to myself at http://wp-wok-imager.googlecode.com/
- Marc
hi.
maybe someone can help me?! i have mentiond that this plugin will only work with local img-files…is there a work-around with external jpg’s. i wanna use e. g. a flickr-link to my pictures and create thumbnails of them.
thanks for reading this…
Hi toul,
At the moment the plugin doesn’t support resizing images that are not local. I filed a feature request to myself for adding it.
- Marc
Awesome. Thats kind of what I was looking for over the last days. I’ll definitely give it a try.
I’d love to have the possibility to import flickr-pictures as well though.
Shouldn’t be too complicated: just a routine that checks, if the file is local or not. If not, fileopen & save it to uploads folder and do the trick. Huh?
wow, if this works the way it seems to then its definitely saving me some serious hours of work! going to give it a try!
it’s working, thanks! but i’m trying to get this to work with an image that i’m posting using custom fields. i am getting the md5.jpg.tag file but the resized md5.jpg file does not exist. the src attribute in the image tag is changed correctly and leads to the nonexistant md5.jpg. would you happen to have any suggestions on solving this?
Hi Marc,
Excellent plugin - for me not so much for the resizing, but the filters.
My question, is there a way of making it only target images of a certain class, and not every img on the page?
I’d like to use it to apply the gray filter to post thumbnails, but don’t want the plugin to touch any of the images elsewhere on the page.
Cheers.
Following up on my question, I found a way so it only affects images that have been given a filter (leaving all other images). Just modified this bit of code in wok-imager.php, removing the height and width calls:
if ( strpos($img_element, ‘width=’)
|| strpos($img_element, ‘height=’)
|| strpos($img_element, ‘filter=’))