|
|
|
|
|
This code is used to generate thumbnails on fly in proportion to the original image size to keep the quality of the image.
Supported image formats : jpeg and png.
image.php
| <?php
$image_base = explode('.', imagepath);
$image_ext = $image_base[1];
$img_path= $imagepath;
if(strtolower($image_ext) == 'jpg') {
$oImage = imagecreatefromjpeg($img_path);
}elseif(strtolower($image_ext) == 'png') {
$oImage = imagecreatefrompng($img_path);
}
$old_x=imagesx($oImage);
$old_y=imagesy($oImage);
if($old_x>=$old_y){
$original_aspect_ratio=$old_x/$old_y;
$width_max=true;
}elseif($old_x<$old_y){
$original_aspect_ratio=$old_y/$old_x;
$height_max=true;
}
if($old_x<=$width && $old_y<=$height){
$thumb_w=$old_x;
$thumb_h=$old_y;
}else{
if($old_x>=$old_y){
$height=$height/$original_aspect_ratio;
$thumb_w=$width;
$thumb_h=$height;
}elseif($old_x<$old_y){
$width=$width/$original_aspect_ratio;
$thumb_w=$width;
$thumb_h=$height;
}
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$oImage,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if(strtolower($image_ext) == 'jpg') {
imagejpeg($dst_img);
}elseif(strtolower($image_ext) == 'png') {
imagepng($dst_img);
}
?> | |
Usage Exmaple
| //The width and height are the size of the window where the image is to be displayed.
<img src="image.php?imagepath=path&width=200&width=300"> | |
|
|
| crop and resize image class using gd library function Categories : PHP, PHP Classes, GD image library, Graphics | | | 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 | | | Create a Thumbnail Using PHP, GD and Exif Categories : PHP, Graphics, Exif, GD image library | | | Advanced Image WaterMarker Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented | | | PHP Email image generator - hide your email from bots - using the GD Library Categories : PHP, Graphics, GD image library, Beginner Guides | | | Image Generation Class ( PNG Format ) Categories : PHP, GD image library, PHP Classes, Graphics | | | Line graphics generation library written in PHP + GD library (spanish comments) Categories : PHP, Graphics, GD image library | | | 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 | | | Simple PHP Bar Graph using GD library Categories : PHP, GD image library, Graphics, Arrays | | | 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 | | | imageMarker v 3.00 with new advanced features Categories : PHP, PHP Classes, Graphics, GD image library | | | 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 | | | CAPTCHA[Image verification] Categories : PHP, Security, GD image library, Graphics, Sessions | |
| |
| |
|