submit to reddit

cursor-resize

Ever since I discovered PHP I tried to simplify everything by splitting files into most used parts and using include() to add them, reading files from directories and generating galleries on the fly, or by using many tricks to make my developer life easier.

Today, I’ll show you how to use PHP and GD library to show perfectly cropped thumbnails for your large images. This script even creates a cache folder, so the next time a user visits your site, the images will be retrieved automatically.

I’m using a script called Smart Image Resizer, the current version being 1.4.1. You can download it from the author’s page, or from here.

Each time you need to display a thumbnail, you call the image.php script like this:

<a href="/php_smart_image_resizing_thumbnails_on_the_fly/images/image.jpg"><img src="/php_smart_image_resizing_thumbnails_on_the_fly/imagephp/image_width_75_ampampheight_75_ampampcropratio_11_ampampquality_100_ampampimage_httpdomain.comimagesimage.jpg.jpg" alt="" /></a>

You need to use a full path for the image parameter. The other parameters are self-explanatory. My example will show a square thumbnail, 75px*75px, and a quality of 100 out of 100. The cropratio parameter tells the script to generate a square thumbnail by cropping the wider sides.

That’s it! Good luck.

3 Responses to PHP Smart Image Resizing – Thumbnails On The Fly

  • I am using phpThumb on a website of mine. I chose this one because of 5 main reasons:

    1. it uses cache
    2. it can output 5 formats: jpg, gif, png, bmp, ico
    3. phpThumb’s basic features will work even if the server has no GD support, as long as ImageMagick is installed
    4. It can apply (if necessary) a non-permanent watermark on any picture
    5. A number of filters can be applied (most require GD v2.0+ and/or PHP v4.3+, or ImageMagick)

    I hope that maybe someday this information will be good for anyone who reads your blog constantly ;)
    .-= Specificatii motociclete´s last blog ..Polaris Sportsman 800 EFI =-.

    Reply
  • Hi,
    How would I save the thumbnail to a web server as opposed to displaying on screen?
    (apologies if this is a daft question!)

    Reply
  • This script generates thumbnails on-the-fly. You may be able to save them by using some PHP copying function and copying the thumbs to a directory. I can’t help you with a script like that. Not my area of expertise.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>