I'm trying to resize thumbnails with external gd code, but it seems the images are not correctly read.
The image link would look like this.
PHP Code:
tn_image.php?image=attachment.php?attachmentid=56
The code below is saved in tn_image.php
PHP Code:
<?php
// make thmubnail of image
function sizeImage($image, $x, $y, $proportional) {
if (!$attr = getimagesize($image)) {
trigger_error("GD: Image does not exist. Must be gif, jpeg, or png!",E_USER_ERROR);
}
switch ($attr[2]) {
case 1:
$image = imagecreatefromgif($image);
break;
case 2:
$image = imagecreatefromjpeg($image);
break;
case 3:
$image = imagecreatefrompng($image);
break;
default:
trigger_error("GD: Image type wrong. Must be gif, jpeg, or png!", E_USER_ERROR);
}
if ($proportional) {
if ($attr[0]<$attr[1]){
$x = $y * ($attr[0]/$attr[1]);
}
else{
$y = $x / ($attr[0]/$attr[1]);
}
}
$newimage = imagecreatetruecolor($x,$y);
imagecopyresampled($newimage, $image, 0, 0, 0, 0, $x, $y, $attr[0], $attr[1]);
imagepng($newimage);
imagedestroy($image);
imagedestroy($newimage);
}
$image = $_GET['image']; //image location
$x = 150; //width
$y = 100; //height
$proportional = TRUE; //proportional or not
header("Content-type: image/png"); //so we can use the image right in a tag. <img src="image.php?image=me.gif">
sizeImage($image, $x, $y, $proportional);
?>
I already know that attachment.php?attachmentid=56 in the link is the issue, but I have no idea how to solve this. It it actually required to save the image to the hd first before any attachment can be resized? I'd rather do it on the fly.