|
|
|
|
|
|
| |
Function for creating thumbnail
|
<?php
//Create Thumbnail using image
function createThumbs( $pathToImages,$file_name, $pathToThumbs, $thumbWidth){
$pathToImages = $pathToImages.$file_name;
//Function for getting image type
$type = exif_imagetype($pathToImages);
//-------------------------------------------------------------------------
//Imagetype Constants for different image types
//Type = 1 IMAGETYPE_GIF
//Type = 2 IMAGETYPE_JPEG
//Type = 3 IMAGETYPE_PNG
//Type = 6 IMAGETYPE_BMP
//-------------------------------------------------------------------------
switch($type)
{
case 1:
$img = imagecreatefromgif($pathToImages);
break;
case 2:
$img = imagecreatefromjpeg($pathToImages );
break;
case 3:
$img = imagecreatefrompng($pathToImages);
break;
case 6:
$img = imagecreatefromwbmp($pathToImages);
break;
}
// load image and get image size
$width = imagesx( $img );
$height = imagesy( $img );
// calculate thumbnail size
if( $width >=$height) {
//If width is greater than height
$new_width = $thumbWidth;
$new_height = floor( $height * ( $thumbWidth / $width ) );
}else{
//If height is greater than width
$new_width = $thumbWidth;
$new_height = floor( $width * ( $thumbWidth / $height ) );
}
// create a new temporary image
// echo $new_height;
$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
switch($type){
case 1:
$img = imagegif( $tmp_img, $pathToThumbs.$file_name);
break;
case 2:
$img = imagejpeg( $tmp_img, $pathToThumbs.$file_name);
break;
case 3:
$img = imagepng($tmp_img, $pathToThumbs.$file_name);
break;
case 6:
$img = imagewbmp($tmp_img, $pathToThumbs.$file_name);
break;
}
$file_name = $src_img = $pathToThumbs.$file_name;
}
?> | |
usage example
| <?php
//Creating thumbnail of image using function
//100 is the width of the thumb nail
createThumbs("../watermark_image/",$prodImage1,"../watermark_image/thumbs/",100);
?> | | |
|
| Create Thumbnails - resize an image - jpeg, jpg, gif, png to the specifed width and height in proportion without loosing out on pixcel quality. Categories : PHP, GD image library, Graphics | | | PHP Email image generator - hide your email from bots - using the GD Library Categories : PHP, Graphics, GD image library, Beginner Guides | | | Advanced Image WaterMarker Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented | | | Line graphics generation library written in PHP + GD library (spanish comments) Categories : PHP, Graphics, GD image library | | | A captcha image allows you to prevent spam posting when users reload the page and stop bots from submitting forms automatically. This version allows you to use your own fonts (.ttf) to show the text.
Categories : PHP, Security, Graphics, GD image library | | | Simple PHP Bar Graph using GD library Categories : PHP, GD image library, Graphics, Arrays | | | Image Generation Class ( PNG Format ) Categories : PHP, GD image library, PHP Classes, Graphics | | | EasyPhpThumbnail Class - The EasyPhpThumbnail class allows you to generate thumbnails and handle image manipulation for GIF, JPG and PNG on-the-fly. Categories : PHP, PHP Classes, Object Oriented, Graphics, GD image library | | | PHP Image Compression using GD library Categories : PHP, Compression, GD image library, Graphics | | | a simple pie-chart in php3 (with gd) Categories : PHP, Graphics, GD image library, Charts and Graphs | | | Display a bar chart based on random values. Categories : Graphics, PHP, GD image library, Charts and Graphs | | | CAPTCHA[Image verification] Categories : PHP, Security, GD image library, Graphics, Sessions | | | imageMarker v 3.00 with new advanced features Categories : PHP, PHP Classes, Graphics, GD image library | | | Simple class that uses GD to draw pie charts. After the class definition there's some sample code to demonstrate how you use the class.
Categories : Graphics, PHP, PHP Classes, GD image library, Charts and Graphs | | | Generate image with random number (CAPTCHA) Categories : PHP, GD image library, Graphics, Security | |
|
|