Apparently getimagesize() is a neat function built into PHP, but it’s also slow as molasses and requires the use of an fopen property some servers have disabled. Enter cURL.
You can use cURL and a function to return the width and height of an image VIA a URL. The code below is a cluster of something I found online, with a mix of my own magic.
// Function that does some cURLing to determine the images size without using getimagesize()
if(!function_exists( ‘curlsizer’ )) {
function curlsizer( $rawImage ){$header = array(
“Range: bytes=0-32768″
);$ch = curl_init( $rawImage );
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
return curl_exec( $ch );
curl_close( $ch );}
}// I work out…
$raw = curlsizer($rawImage);
$im = imagecreatefromstring($raw);
$width = imagesx($im);
$height = imagesy($im);echo $width.’<br/>’.$height;
