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

后端 未结 5 714
旧时难觅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:16

    This also works:

    $img = imagecreatetruecolor(100,100);
    
    // ... processing
    
    ob_start();              // start the buffer
    imagejpeg($img);         // output image to buffer
    $size = ob_get_length(); // get size of buffer (in bytes)
    ob_end_clean();          // trash the buffer
    

    And now $size will have your size in bytes.

提交回复
热议问题