PDA

Click to See Complete Forum and Search --> : problem creating a thumbnail


ai.unit
Feb 24th, 2003, 03:14 AM
hi!
i'm creating a foto album, and want to generate the thumbnails dynamically, so i got the code below which takes the url of an image and creates a small version of it.
for some reason it is not working, can you please help me finding the error?

you can try it here:
http://yusran.com/php/php.exe/getthumb.php?url=http://sam.yusran.com/yusran/krbt/krbtSambi.nsf/friends5.jpg


here's my complete php code


<?php
if (isset($_GET['url'])) {
$max_x = 150;
$max_y = 150;
return loadjpeg($_GET['url'], $max_x, $max_y);
}


function loadjpeg($path, $max_x, $max_y) {
$im = @imagecreatefromjpeg($path);
if (!$im) {
$im = imagecreate(150, 30);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
imagestring($im, 1, 5, 5, "Error loading $path", $tc);
}

if ($max_x != 0 && $max_y != 0) {
$x = imagesx($im);
$y = imagesy($im);

if ($x > $max_x) {
$y = (int)floor($y * ($max_x / $x));
$x = $max_x;
}

if ($y > $max_y) {
$x = (int)floor($x * ($max_y / $y));
$y = $max_y;
}

if (imagesx($im) != $x || imagesy($im) != $y) {
$tmp = imagecreate($x, $y);
imagecopyresized($tmp, $im, 0, 0, 0, 0, $x, $y, imagesx($im), imagesy($im));
imagedestroy($im);
$im = $tmp;
}
}

return $im;
}
?>



thank you :)

phpman
Feb 24th, 2003, 02:45 PM
good luck, I couldn't get that to work either. I know you got it right out of the php manual too.

I think you have to have the most current GD library as well.