Here I will show you guys how to create a thumbnail from a larger image file ( .jpg file)
You create a new .php file, and enter this function:
-
<?php
-
-
function thumbnail($file, $size, $save_as) {
-
-
$modwidth = $width * $size;
-
$modheight = $height * $size;
-
$tn = imagecreatetruecolor($modwidth, $modheight) ;
-
$image = imagecreatefromjpeg($file) ;
-
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
-
imagejpeg($tn, $save_as, 100) ;
-
}
-
-
?>
then you can call the function like this:
-
<?php
-
-
thumbnail(‘original_image.jpg’, ‘0.60′, ‘new_image.jpg’);
-
-
?>
The last part calls the function, and tells it to create a thumbnail from the “original_image.jpg”, with 0.6 the size of the original, and store the new image as “new_image.jpg” in the same folder as the script.
Some of the code in the function is explained in this post.
Simple 