Displaying thumbnail image through php script in desired dimension

3 views
Skip to first unread message

zeesh...@gmail.com

unread,
Apr 30, 2007, 4:07:47 PM4/30/07
to phpguru
Example: thumbnail.html
<IMG SRC="thumbnail.php?image=../photo/yourphoto.jpg&width=10" />

thumbnail.php

<?php
set_time_limit(0);
header("Content-type:image/jpeg");
// get image size
$file = $_GET[image];
if($size = GetImageSize($file)){
$w = $size[0];
$h = $size[1];
//set new size
$nw = $_GET['width'];
$nh = ($nw*$h)/$w;
}
else{
//set new size
$nw = "0";
$nh = "0";
}
//Now let's draw the image:
//draw image
$src_img = imagecreatefromjpeg($file);
$dst_img = imagecreatetruecolor($nw,$nh);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $w, $h);
imagejpeg($dst_img,"",100);
imagedestroy($src_img);
imagedestroy($dst_img);
?>

Reply all
Reply to author
Forward
0 new messages