|
Posted by Charlie King on 12/23/05 17:04
in brief:
Can I perform operations like imagesx() or getimagesize() on raw image
data as retrieved into a variable from a database, without first
saving it as a file? If so, how? If not, what is the best way to
create a temporary file such that it is unlikely to conflict with
other sessions that are performing the same actions?
in more detail:
I have a database that stores an image in a BLOB field, and I want to
display that image on my page either 'as is' or as a thumbnail created
on the fly to a width passed to the <img...> tag by means of a $_GET
variable - so either
<img src="getimage.php?imageid=0123 />
in the first instance, or
<img src="getimage.php?imageid=0123&action=thumb&width=200 />
in the second.
I'm getting the image from the database like this:
$photoFetchSource = $_GET["imageid"];
$photoFetchQuery = "SELECT * FROM mytable WHERE
photoid=".$photoFetchSource;
$photoFetchResult = mysql_query($photoFetchQuery) or die("blah...");
$photoFetchArray = mysql_fetch_assoc($photoFetchResult;
$photo = $photoFetchArray["photo"];
and I can send the unchanged photo to the page by
header ("Content-type: image/jpg");
echo $photo;
So far, so good...
Unfortunately, I can't do things like
list($width, $height, $type, $attr) =
getimagesize($photo)
because '$photo' isn't a file.
I'd like to avoid any unnecessary file operations if I can. Any
suggestions?
--
Charlie
Navigation:
[Reply to this message]
|