Page 1 of 1

how to obtain byte stream from an image resource

Posted: Sun May 16, 2004 4:39 am
by davidklonski
Hello

I have generated an image resource using imagecopyresampled.
Is there a simple way to obtain the byte stream of that resource?

An indirect method would be to store the image to a file like so:

Code: Select all

// assuming this is a jpeg
ImageJPEG($resource, $filename);
// read the byte stream using fread
$stream = fread(fopen($filename, "r"), filesize($filename));
This method is awkward because it may be slow (generating a file) and I would need to delete the file afterwards.

is there a better way?

My ultimate goal is to save the byte stream as a blob in the database.

thanks in advance

Posted: Sun May 16, 2004 11:21 am
by feyd
I believe,

Code: Select all

$stream = ImageJPEG($resource)
where $stream is now the data you seek. I think...