Do it simpler : Image thumbnail and resize in PHP

 

resizeOne of the common complex task among webdevelopers is image resizing. It is a big headach when using multiple size images in multiple pages of a single version of image. For long I was using a an script that would create one thumnail version of the image when the image is uploaded. It was not a suitable solution. Many time we will need different size of thumbnails to be used in different location and pages.

I came across PHPThumb. It was a very much better one for me where it can deliver following types of resizing mechanism.

  • adaptiveResize ($width, $height)
  • crop ($startX, $startY, $cropWidth, $cropHeight)
  • cropFromCenter ($cropWidth, $cropHeight = null)
  • resize ($maxWidth, $maxHeight)
  • resizePercent ($percent)
  • rotateImage ($direction = ‘CW’)
  • rotateImageNDegrees ($degrees)
  • save ($fileName)
  • show ()

You can learn more about this script here

Well,I have written a simple script that can work with phpThumb. What it would do is, when I request for a resized version of an original image, it will check for a same resized version. If the one resized version exist, it will return the path of that. Otherwise, a new resized version will be created and saved before returning the path. This will help to use any size of thumbnail image at any time without wasting match resources.

The script

 

How to use this function?
scenario : Need a adaptive resize verion for /img/catalogue/sample1.jpg at 120px x 100px

 

solution :

This will generate a “adaptive” resized image at the size of 120 px width and 100 px height.

This iamge will have the path

This script might helpful you too. Please do not forget to put a comment if you like it Or any suggestion if you have.

One comment Add yours
  1. What I use to great acefft is the program blogjet. It has built in margins for images, lets you write offline, and save posts to your hard drive. As one who is constantly multitasking, this is a lifesaver.Tom

Leave a Reply

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


*

Please wrap all source codes with [code][/code] tags.