Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I suggest you follow this approach:</p> <pre><code>// if you need the image type $type = exif_imagetype($url); // if you need the image mime type $type = image_type_to_mime_type(exif_imagetype($url)); // if you need the image extension associated with the mime type $type = image_type_to_extension(exif_imagetype($url)); // if you don't care about the image type ignore all the above code $image = ImageCreateFromString(file_get_contents($url)); echo ImageSX($image); // width echo ImageSY($image); // height </code></pre> <p>Using <code>exif_imagetype()</code> is a lot faster than <code>getimagesize()</code>, the same goes for <code>ImageSX()</code> / <code>ImageSY()</code>, plus they don't return arrays <strong>and</strong> can also return the correct image dimension after the image has been resized or cropped for instance.</p> <p>Also, using <code>getimagesize()</code> on URLs isn't good because it'll consume much more bandwidth than the alternative <code>exif_imagetype()</code>, from the <a href="http://pt.php.net/manual/en/function.exif-imagetype.php" rel="noreferrer">PHP Manual</a>:</p> <blockquote> <p>When a correct signature is found, the appropriate constant value will be returned otherwise the return value is FALSE. The return value is the same value that <code>getimagesize()</code> returns in index 2 but <code>exif_imagetype()</code> is much faster.</p> </blockquote> <p>That's because <code>exif_imagetype()</code> will only read the first few bytes of data.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload