Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function createAThumbnail ($path, $thumbPath , $fname, $thumbWidth)
- {
- // parse path for the extension
- $info = pathinfo($pathToImages . $fname);
- // continue only if this is a JPEG image
- if ( strtolower($info['extension']) == 'jpg' )
- {
- 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;
- $new_height = floor( $height * ( $thumbWidth / $width ) );
- // 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
- // phpinfo();
- //echo "<img src=$thumbPath$fname>";
- $fname = "thumb_".$fname;
- imagejpeg( $tmp_img, $thumbPath.$fname );
- echo "created thumb";
- }
- }//createAThumb
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement