Hi, I am trying to create a PHP thumbnail script, but I am getting a few errors. I hope someone can help me out. This is the code: As you can see I am trying to make a thumbnail from an image called "Sig.jpg". This are the errors I get: What's the problem? Thanks in advance.
<?php $image = "Sig.jpg"; $image = imagecreatefromjpeg($image); $width = imagesx($image); $height = imagesy($image); if ($width = $height) { $new_width = 150; $new_height = 150; } elseif ($width > $height) { $new_width = 150; $new_height = $height * ($new_width/$width); } elseif ($width < $height) { $new_height = 150; $new_width = $width * ($new_height/$height); } $thumb = imagecreatetruecolor($new_width,$new_height); imagecopyresampled($thumb,$image,0,0,0,0,$new_width,$new_height,$width,$height); imagejpeg($thumb,$file."_thumb".$type); ?> PHP: Also, you haven't defined $type for the 'imagejpeg' function.
You are not pulling in the image. You are just assigning a file name to the $image variable. http://www.php.net/imagesx Scroll down the page to the comments. If you are working with a JPG, you need to use $img = ImageCreateFromJpeg($image); for a GIF use: $img = ImageCreateFromGif($image); for a PNG use: $img = ImageCreateFromPng($image);
<?php header('Content-type: image/jpeg'); list($width, $height) = getimagesize("image.jpg"); $a = imagecreatetruecolor(100, 100); $b = imagecreatefromjpeg($filename); imagecopyresampled($a, $b, 0, 0, 0, 0, 100, 100, $width, $height); imagejpeg($a, null, 100); ?> This code will generate 100x100 big thumbnain