Thumbnail Generation from DB Stored Images.
| From: | Jason Bell | Date: | Thu, 12 Jul 2001 23:26:37 +0000 |
| Subject: | Thumbnail Generation from DB Stored Images. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-57649@lists.php.net to get a copy of this message | ||
Hello! I have images stored in a MySQL Database. I can retrieve the images and display them without
a problem, but I'd really like to be able to create thumbnails. The code that I've written
just doesn't seem to work. Preferably, I'd like to pull the image from the database, and
create the thumbnail for display, without ever writing an image to the disk. If this is not
possible, I'd like to know alternate methods. I'm using imagemagick's convert utility
to create the thumbs. Here is my code:
getpic.php:
<?php
if($id) {
@MYSQL_CONNECT("localhost","username","mypassword");
@mysql_select_db("daelic");
$query = "select image,type from images where id=$id";
$result = @MYSQL_QUERY($query);
$data = @MYSQL_RESULT($result,0,"image");
$type = @MYSQL_RESULT($result,0,"type");
Header( "Content-type: $type");
echo $data;
};
?>
tgen.php:
<?php
if ($id) {
$src = getpic.php?id=$id;
$thumb = passthru("convert -geometry 40% $src jpeg:-");
print $thumb;
};
?>
I know that getpic.php works. I can use it in like this: echo "<IMG
SRC='getpic.php?id=$id'>"; and it will output the fullsize graphic in place.
I'm trying to get to a point where I can use tgen.php in the same mannor. I can use the same
convert command if I use an actual file, like pics/mypic.jpg and it works, so the command is
good.....
any help at all would be very appreciated,
Jason Bell