Panjabel Posted June 26, 2007 Share Posted June 26, 2007 getimagesize function work so slow, is there a fast way to get the image size ? thanks Quote Link to comment https://forums.phpfreaks.com/topic/57253-getimagesize-too-slow-why/ Share on other sites More sharing options...
redarrow Posted June 26, 2007 Share Posted June 26, 2007 <?php // outputs e.g. somefile.txt: 1024 bytes $filename = 'somefile.txt'; echo $filename . ': ' . filesize($filename) . ' bytes'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/57253-getimagesize-too-slow-why/#findComment-282975 Share on other sites More sharing options...
Panjabel Posted June 26, 2007 Author Share Posted June 26, 2007 $size = getimagesize("$photo"); $height = $size[1]; $width = $size[0]; if ($height<=$width){ print "<img width='120' src='$photo'>"; } else { print "<img height='100' src='$photo'>"; } why this code works so slow ? Quote Link to comment https://forums.phpfreaks.com/topic/57253-getimagesize-too-slow-why/#findComment-282981 Share on other sites More sharing options...
TreeNode Posted June 26, 2007 Share Posted June 26, 2007 Is the file local? I know when considering the GD library and images in general with PHP has some problems when trying to get images from non-local machines. Quote Link to comment https://forums.phpfreaks.com/topic/57253-getimagesize-too-slow-why/#findComment-282982 Share on other sites More sharing options...
Panjabel Posted June 26, 2007 Author Share Posted June 26, 2007 Hello bro the file is not local, do you think this is the main problem, because the file is not local ? thanks ... yes, that right thank you master TreeNode Quote Link to comment https://forums.phpfreaks.com/topic/57253-getimagesize-too-slow-why/#findComment-282986 Share on other sites More sharing options...
TreeNode Posted June 26, 2007 Share Posted June 26, 2007 If you are in fact using an older version of PHP (4.0 or earlier) you'll definitely have problems. Try this code that was directly from PHP.net, it might not be the best but it should work as a more manual way of getting information about a remote file: function getimagesize_remote($image_url) { $handle = fopen ($image_url, "rb"); $contents = ""; if ($handle) { do { $count += 1; $data = fread($handle, 8192); if (strlen($data) == 0) { break; } $contents .= $data; } while(true); } else { return false; } fclose ($handle); $im = ImageCreateFromString($contents); if (!$im) { return false; } $gis[0] = ImageSX($im); $gis[1] = ImageSY($im); // array member 3 is used below to keep with current getimagesize standards $gis[3] = "width={$gis[0]} height={$gis[1]}"; ImageDestroy($im); return $gis; } Another option is to do what I do, create another script on the server that houses the images, that script is just a function that can either manipulate an image and cache it or just return the image information. Quote Link to comment https://forums.phpfreaks.com/topic/57253-getimagesize-too-slow-why/#findComment-283004 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.