I'm resizing images with php gd. The result is image resources that i want to upload to Amazon S3. It works great if i store the images on disk first but i would like to upload them directly from memory. That is possible if i just know the bytesize of the image.
Is there some way of getting the size (in bytes) of an gd image resource?
This also works:
And now
$size
will have your size in bytes.I can't write on php://memory with imagepng, so I use ob_start(), ob_get_content() end ob_end_clean()
You might look at the following answer for help. It works for generic memory changes in php. Although since overhead could be involved it might be more of an estimation.
Getting size of PHP objects
Save the image file in the desired format to a tmp dir, and then use filesize() http://php.net/manual/de/function.filesize.php before uploading it to S3 from disk.
You could use PHP's memory i/o stream to save the image to and subsequently get the size in bytes.
What you do is:
Now you should know the size
I don't know of any (gd)method to get the size of an image resource.