Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've modified the @Volomike's code to get width too. Here you go...</p> <pre> function get_image_dim($sURL) { // note that for jpeg you may need to change 300 to a larger value, // as some height/width info is farther out in the header try { $hSock = @ fopen($sURL, 'rb'); if ($hSock) { while(!feof($hSock)) { $vData = fread($hSock, 300); break; } fclose($hSock); if (strpos(' ' . $vData, 'JFIF')>0) { $vData = substr($vData, 0, 300); $asResult = unpack('H*',$vData); $sBytes = $asResult[1]; $width = 0; $height = 0; $hex_width = ''; $hex_height = ''; if (strstr($sBytes, 'ffc2')) { $hex_height = substr($sBytes, strpos($sBytes, 'ffc2') + 10, 4); $hex_width = substr($sBytes, strpos($sBytes, 'ffc2') + 14, 4); } else { $hex_height = substr($sBytes, strpos($sBytes, 'ffc0') + 10, 4); $hex_width = substr($sBytes, strpos($sBytes, 'ffc0') + 14, 4); } $width = hexdec($hex_width); $height = hexdec($hex_height); return array('width' => $width, 'height' => $height); } elseif (strpos(' ' . $vData, 'GIF')>0) { $vData = substr($vData, 0, 300); $asResult = unpack('h*',$vData); $sBytes = $asResult[1]; $sBytesH = substr($sBytes, 16, 4); $height = hexdec(strrev($sBytesH)); $sBytesW = substr($sBytes, 12, 4); $width = hexdec(strrev($sBytesW)); return array('width' => $width, 'height' => $height); } elseif (strpos(' ' . $vData, 'PNG')>0) { $vDataH = substr($vData, 22, 4); $asResult = unpack('n',$vDataH); $height = $asResult[1]; $vDataW = substr($vData, 18, 4); $asResult = unpack('n',$vDataW); $width = $asResult[1]; return array('width' => $width, 'height' => $height); } } } catch (Exception $e) {} return FALSE; } </pre> <p>So, using it we have...</p> <pre> // jpeg $url = 'http://upload.wikimedia.org/wikipedia/commons/thumb/c/ce/Quality_comparison_jpg_vs_saveforweb.jpg/250px-Quality_comparison_jpg_vs_saveforweb.jpg'; // png //$url = 'http://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png'; // gif //$url = 'http://upload.wikimedia.org/wikipedia/commons/e/e2/Sunflower_as_gif_small.gif'; $dim = get_image_dim($url); print_r($dim); </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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