Norman Peelman wrote:
The Natural Philosopher wrote:
>I have a databse containing amongst other things many images stored as
BLOBS.
When listing, currently I download all the images full size and let he
browser do the reduction to thumbnails.
It's getting a little slow on long lists.
Is there anyway to take the data and scale it down on the fly to a
smaller image? I have plenty of processor power, just not much bandwidth.
The images are a mixture of GIF, JPEG and PNG.
imagecreatefromstring() is your friend. Then just resize to your liking
and output as normal.
Well MANY thanks..
After struggling to get Gdlib on one machine..it was magically on the
other..I didn't realise that php5-gd was an extra debian package
the final send-thumbnail.php is, with obvious inclides to access
databases etc, as follows.
It sends a 100PX wide picture of anything it understands in the
database: speed is about ten times greater than with the original mostly
480px wide images.
The actual code that calls the sub file is
<?
printf("<IMG src=\"send_thumbnail.php?id=%d\"
width=\"100px\">",$product_id);
?>
and send_thumbnail.php itself is..
<?php
$privilege_level=0; // only we an access anything..external users must
match,
include('shoplib.php'); // deals with privilege levels and database
opening..
// include('mimelib.php'); //Always use JPEG now!!
open_database(); // ready to check
$id=$_GET['id'];
$query="select picture from product where id='".$id."'";
//echo $query;
$result=mysql_query($query);
if(($result>0) && (($rows=mysql_numrows($result)) == 1)) //got some data
{
$content=mysql_result($result,0,'picture');
}
else die();
if ($name="") die();
// now to shrink the picture..
$im=imagecreatefromstring($content);
// get sizes
$width=imagesx($im);
$height=imagesy($im);
// our thumbnails are 100px wide..dont care about the height so scale as
width
$newheight=round(($height*100)/$width);
$newwidth=100;
$thumbnail=imagecreatetruecolor($newwidth,$newheig ht); // make empty new
wotsit.
imagecopyresampled($thumbnail,
$im,0,0,0,0,$newwidth,$newheight,$width,$height);
header("Content-Type: image/jpeg");
imagejpeg( $thumbnail,null,75);
?>