How to get image resource size in bytes with PHP and GD?

后端 未结 5 715
旧时难觅i
旧时难觅i 2020-12-10 06:42

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 up

5条回答
  •  长情又很酷
    2020-12-10 07:27

    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:

    $img = imagecreatetruecolor(100,100);
    // do your processing here
    // now save file to memory
    imagejpeg($img, 'php://memory/temp.jpeg'); 
    $size = filesize('php://memory/temp.jpeg');
    

    Now you should know the size

    I don't know of any (gd)method to get the size of an image resource.

提交回复
热议问题