Need to generate thumbnails for images? With this single script you can generate a thumbnail of any size on demand. It also caches images so it only generates the thumbnails as needed. You can also crop images to size, or stretch them to fit. You don’t even have to write any PHP.
How to use
Wherever you want a thumbnail, simply change your normal image src to the following…
<img src="/image.php?f=/images/myimage.jpg&w=320" alt="" />
There is also an optional effect parameter.
f = filename of the image, including directories (/absolute/is/best)
w = the width of the image
h = the height of the image
effect = the resize effect. This is optional, defaults to bestfit. Other possible values are crop and stretch
w and h are both required if the effect is crop or stretch, otherwise only one of them is required
Although the input file can be jpg, gif, or png – the output file
will always be a jpg, so you cannot have transparencies or animations
PHP Image Resize
Extract image.php and upload it to your website.
Create a “cache” director and give it 777 permissions
If you’d like to change the cache directory, simply modify the line…
$cacheDir = $_SERVER['DOCUMENT_ROOT'].’/cache/’;
The default image quality is 85%, you can change this also, by modifying this line…
$imageQuality = 85; // 0 (bad quality, small file) to 100 (high quality, big file)
First see if your server is able to generate images. Goto yoursite.com/image.php
If you dont see a “No Image Available” image (like: http://factory8.com/image.php ), then you either didn’t upload the file, or your server doesn’t have GD Lib installed
If you get a broken image, make sure your cache directory is created with the proper permissions (777).
If you are still getting a broken image, make sure your passing a width or height and not just the file.
Please let me know what you think!