|
Posted by Charlie King on 10/18/18 11:35
On 23 Dec 2005 14:08:16 -0800, in
<1135375696.256198.259250@g43g2000cwa.googlegroups.com>
(comp.lang.php) "NC" <nc@iname.com> wrote:
> 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().
Thanks for that - as it turns out, that's exactly where I ended up :)
> > 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);
Spookily similar to the code I have here! lol
> 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.
I'd considered that, but there are two issues - a) those dimensions
have to be calculated at some time, and it's as well to do so on the
way out as the way in (although, arguably they'll be extracted more
frequently than they're input...), and b) there is a possibility that
my customer will end up squirting data into the database from
somewhere other than my web front end, and I'd rather be in control
than their supplying good data.
> Cheers,
> NC
Thanks :)
--
Charlie
Navigation:
[Reply to this message]
|