/ Published in: PHP
URL: http://www.webcheatsheet.com/php/create_thumbnail_images.php
Expand |
Embed | Plain Text
<?php function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth ) { // open the directory // loop through it, looking for any/all JPG files: // parse path for the extension // continue only if this is a JPEG image { echo "Creating thumbnail for {$fname} <br />"; // load image and get image size $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" ); $width = imagesx( $img ); $height = imagesy( $img ); // calculate thumbnail size $new_width = $thumbWidth; // create a new temporary image $tmp_img = imagecreatetruecolor( $new_width, $new_height ); // copy and resize old image into new image imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); // save thumbnail into a file imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" ); } } // close the directory } // call createThumb function and pass to it as parameters the path // to the directory that contains images, the path to the directory // in which thumbnails will be placed and the thumbnail's width. // We are assuming that the path will be a relative path working // both in the filesystem, and through the web for links createThumbs("upload/","upload/thumbs/",100); ?>
Comments
Subscribe to comments
You need to login to post a comment.

check this one out http://freelogic.pl/thumbnailer/