I’m using imagecreatefromjpeg(), imagecreatefrompng() and imagecreatefromgif() to convert some image files and want to know the filesize of the image after conversion. I’ve tried filesize(imagecreatefrompng(filename)) and getimagesize() – but none of them seem to work. Is there another way?
I’m using imagecreatefromjpeg(), imagecreatefrompng() and imagecreatefromgif() to convert some image files and want to
Share
filesize()andgetimagesize()expect a filename.imagecreatefromwhatever()returns a GD file handle. You cannot feed one into the other. You’d need to save your image to a file, then use filesize on that new file, or use the output buffering mechanism to capture the output of the save functions and do a strlen on that, e.g.or
There is no other practical method to determine the final image size WITHOUT producing that file in the first place – PNG/JPG output compression depends heavily on the content of the image – “simple” images will compress far more than “busy” images.