Image resizing on the fly using PHP

Smart Image Resizer 1.4.1

this is one of the best PHP scripts I‘ve found so far on the internet. It‘s made under the Creative Commons license. All he asks is to include a link on your website to his website when you use his script http://shiftingpixel.com. It allows you to crop or scale an image on the fly only by setting a certain width, height and if necessary a cropratio. If you, for example, change the layout of your website and the images need to be larger, you don‘t need to scale the images all over again. Just change the parameters and the images will be cropped to that size. The original images aren‘t modified in the process. I‘ve incorporated this script in the CMS from webFizz and saved me a lot of time so far. 

installation:

copy the image.php file to your imagefolder. 

Make a folder with the name imagecache (you can manually change the name of the folder in the image.php file)

To change the folder just change the constant‘s value to the name you desire.

define('CACHE_DIR_NAME','/imagecache/');

Make sure you set the permissions on the folder to chmod 777 otherwise it won‘t be able to write the files in this folder

Resizing a JPEG:

img src="/image.php/image.jpg?width=200&height=200&image=/uploads/image.jpg" />

Cropping an image:

img src="/image.php/image.jpg?width=200&ampheight=200&cropratio=1:1&image=/uploads/image.jpg" />

 

You can download the files below. Don‘t forget to change the path to your image. 

remove ’/imageresizer’ if your image folder is located at the root level.

Download demo files

Comments

Posted on 22-03 by pavan

hii.. the image resize script is very nice. but my problem is, Mine is a shopping cart application which uses smarty templates, i need to resize images coming from the DB in tpl file.heres my image tag, is it possible to edit this??? can you please help me out to resize my images... awaiting your valuable suggestions. many thanks for hearing me..

Posted on 15-01 by Rizvi Iqubal

there is mistake in the example usage shown It worked for me only when i used like this

Posted on 22-01 by Steven Dobbelaere

I also use Smarty templates, so just input your filename in a Smarty variable like so: img src="/image.php/{$IMAGE_FILENAME}?width=200&height=200ℑ=/uploads/{$IMAGE_FILENAME}" />

Posted on 13-07 by Dan

How can I make this work when a user uploads an image to our server. When they do upload their profile picture, it does this through a form so I never use an img tag. Instead it's an input tag of type 'file.' So will this work with that, or should I look somewhere else?

Leave a comment