Resizing pics on the fly with NetPbm

hknight

Joined: 2003-08-21
Posts: 7
Posted: Thu, 2003-08-21 19:43

I need thumbnails to be dynamically and instantly created on the fly.

My server supports GD and NetPbm. I tried a program that uses GD but the pictures looked aweful!

<?
header("Content-type: image/gif");
$imagem = $_GET['img'];

$max_x = "59";
$max_y = "40";

$im = imagecreatefromjpeg($imagem);

//rescale proportionaly
// from php.net
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;
}
}

$img_dest = imagecreate($x,$y);
imagecopyresized($img_dest,$im,0,0,0,0,$x,$y,imagesx($im),imagesy($im));
imagejpeg($img_dest);
?>

Is there a way, using PHP and NetPbm that I can call an image like this:

<img src="thumb.php?image=pic.jpg&height=20>

So that a 20 pixal high jpg thumbnail of pic.jpg is returned?

I need it to support both JPG, GIF and PNG images.

 
beckett
beckett's picture

Joined: 2002-08-16
Posts: 3474
Posted: Fri, 2003-08-22 12:33

Why not grab the code from Gallery?

In gallery/util.php, look at the resize_image() function.

You'll need to modify it a bit, but you can have the function return the sized image directly, so you feed the thumb directly to the page, and don't have to save it. The nice thing about this is about 85% of your work is done for you already, and it supports all those three types out of the box.

-Beckett (

)