|
|
|
|
Like this code?
Show the author your appreciation.
|
|
| |
If you have one image file on the server which is like 800 x 600 or more and you want to make 7 copys in diff sizes to display it in various places. creating 7 copys of the image will be over crowding your server space. Use Image Streams to dynamic generate the image.
use this script and pass 3 param :
1. file : <path_to_filename>
2. width : <ma_width_to_reduce>
3. s=1 ( use this for a higher quality)
This code is written using the GD library 1.8. make sure u've got that ext installed.
| <?php
header("Content-Type: image/jpeg");
function getExtension($file){
if(($pos = strrpos($file,"."))!==false)
return strtolower(substr($file,$pos+1,strlen($file)));
}
$filename=$_REQUEST[`file`];
$max_width=$_REQUEST[`width`];
if($_REQUEST[`s`]==`1`) {
$withSampling=true;
}else{
$withSampling=false;
}
// Get new sizes
list($width, $height) = getimagesize($filename);
//-- dont resize if the width of the image is smaller or equal than the new size.
if($max_width!="") {
if($width<=$max_width) $max_width=$width;
$percent = $max_width/$width;
$newwidth = $width * $percent;
$newheight = $height * $percent;
}
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$ext = strtolower(getExtension($filename));
if($ext==`jpg` || $ext==`jpeg`) $source = imagecreatefromjpeg($filename);
if($ext==`gif`) $source = imagecreatefromgif($filename);
if($ext==`png`) $source = imagecreatefrompng($filename);
// Resize
if($withSampling) imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
else imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
if($ext==`jpg` || $ext==`jpeg`) imagejpeg($thumb);
if($ext==`gif`) imagegif($thumb);
if($ext==`png`) imagepng($thumb);
imagedestroy($thumb);
?> | | |
|
| 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 | | | Display a bar chart based on random values. Categories : Graphics, PHP, GD image library, Charts and Graphs | | | 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 | | | CAPTCHA[Image verification] Categories : PHP, Security, GD image library, Graphics, Sessions | | | 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 | | | imageMarker v 3.00 with new advanced features Categories : PHP, PHP Classes, Graphics, GD image library | | | Generate image with random number (CAPTCHA) Categories : PHP, GD image library, Graphics, Security | | | Image Generation Class ( PNG Format ) Categories : PHP, GD image library, PHP Classes, Graphics | | | 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 | | | crop and resize image class using gd library function Categories : PHP, PHP Classes, 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 | |
|
|
|