i was looking for some php code that resizes images effectively creating a thumbnail without resaving and creating a new file. i found this but the problem is that it apparently only works with local urls linking to images files. my images are stored in a mysql database and are retrieved with another php file called "getdata.php?id=x". this php file does work and i can view the original image fine. when i link to http:/mysite.com/pathto/thumbnail.php?url=getdata.php?id=x it gives me this error:
Warning: getimagesize(getdata.php?id=2) [function.getimagesize]: failed to open stream: No such file or directory in /home/public_html/path/thumbnail.php on line 7
this is code for thumbnail.php:
// Get image info from variable
$url = $_GET['url'];
$img = getimagesize($url) or die();//line 7
// Checks if URL is image
if ( $img[2] == 1 ) {
$pic = imagecreatefromgif( $url ) or die();
} elseif ( $img[2] == 2 ) {
$pic = imagecreatefromjpeg( $url ) or die();
} elseif ( $img[2] ==3 ) {
$pic = imagecreatefrompng( $url ) or die();
} else {exit();}
// If an image is found and we can determine that it is an image
if ($pic) {
// Get width and height from the image
$width = imagesx($pic);
$height = imagesy($pic);
$theight = 100;
// Calculate the new width
$twidth = ($theight * $width) / $height;
// Create new image
$thumb = @imagecreatetruecolor ( $twidth, $theight )
or die ("Can't create Image!");
// Resize the image into a thumb
imagecopyresized($thumb, $pic, 0, 0, 0, 0,
$twidth, $theight, $width, $height);
// Change page type to a jpeg
header ("Content-type: image/jpeg");
// Create jpeg image from thumbnail
imagejpeg($thumb,"",75);