Reply to Re: Manipulating image data loaded from SQL database.

Your name:

Reply:


Posted by NC on 10/16/96 11:35

Charlie King wrote:
>
> 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?

You can use getimagesize() only on image files. You can, however, use
imagesx() and imagesy() on any image. What you need to do is to pull
data from the database, create an image using imagecreatefromstring()
and feed the resulting image resource to imagesx() and imagesy().

> 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?

Two. First, you can do this:

$img = imagecreatefromstring($photo);
$x = imagesx($img);
$y = imagesy($img);
header ("Content-type: image/jpg");
echo $photo; // or imagejpeg($img);

Second, if you store images in a database, you may consider storing
image attributes (width, height, and type) in the database as well and
not worry about obtaining them at execution.

Cheers,
NC

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация