Textpattern tips, tutorials and code snippets

Crop and resize images on the fly

To be able to crop images to many different sizes (not just fullsize and thumbnail), you can combine upm_image and Smart Image Resizer, a simple to use php script.

From the SIR site, here is a description of the script:

The major advantage of this script is that it allows me to resize and crop any image on my website without touching the actual image or writing any code. I upload each image once at a high enough resolution and can then reuse it at any size I want, anywhere I want. It doesn’t matter if the images are in a post, on a page, or in a template file–it just works.

Two simple steps:

  1. Upload SIR according to the instructions on their page
  2. Install and activate upm_image

On your textpattern form or page, use the following code:

<txp:upm_article_image form="myImage" />

Create a form called “myImage” and in that form write:

<img src="/image.php?width=390&amp;quality=95&amp;image=<txp:upm_img_full_url />" alt="<txp:upm_img_alt />" />

Additional parameters/options can be found on the SIR page.

Source for the tip is here on the Textpattern forum.

9 Comments Comment feed

This is great! Just what I needed . Thanks for the tip, Kemie.

  • sparkybarkalot
  • 9 March 2009

Thanks for a good tip. The MyImage form as I see it above however, is incorrect. It should look like this (at least this is what worked for me):

<img src=”/image.php/<txp:upm_img_name />?width=290&amp;quality=95&amp;image=<txp:upm_img_full_url />” alt=”<txp:upm_img_alt />” />

In second code example “?” is missing after index.php

Thanks for the tip. This allows my clients to just upload a photo and not have to worry about resizing it first.

Incase other have trouble, I couldn’t get this to work until I wrapped the upm tag in an article tag like this.

<txp:upm_article_image form="myform" />

Does this resize images on the fly? With no caching? Does that slow things down?

Nora – from the feature list of the script: Built-in caching keeps image variations for optimal performance

Thanks to Jason Das and the kind people who have posted a comment about the missing ? in the second code block. It has now been corrected in the article.

  • Tye
  • 19 July 2010

I haven’t been able to connect to Smart Image Resizer for a couple of days now :(

Does anyone use any other image resizers?

I found Tim Thumb and phpimageresize

I was using phpThumb but I think that has been abandoned

Joe Lencioni is trying to expand Smart ImageResize and has create SLIR project hosted on GoogleCode.
I’ve just try it for first time and it works as hell!
Usage is just easy as the previous script.

Add a comment

Use Textile help to style your comments