What a week : getimagesize with URIs

Mar 12, 2004

Been a busy week at work, so I haven't really had much of a chance to script lately. I could release the Knowledgebase soon, but so far I haven't written up the readme.txt file. I should get around to that soon :|

In other news, I bought some stock in Opera Software two days ago :) I have some other stock, but this is the first company I've invested in which affects me personally. I've used Opera for almost a year now and I'd never look at anything else. Especially since I'm on dialup at home, and the Opera download is only 3.7MB! Amazing!

In my nooks and crannies of spare time this week, I found a bit of PHP code which allows you to use URI's in the getimagesize() function. PHP only added support for it in 4.0.5. Most installations of PHP are later than this of course, but it's useful for totally backwards compatibility. I found it on PHP.net but I recoded it for my own use as below:

function getimagesize_remote($image_url) {
  $handle = @fopen($image_url, "rb");
  $contents = "";
  if ($handle) {
    while ($data = fread($handle, 8192)) $contents .= $data;

    $im = imagecreatefromstring($contents);
    if ($im) {
      $gis[0] = imagesx($im);
      $gis[1] = imagesy($im);
      $gis[3] = "width=\"{$gis[0]}\" height=\"{$gis[1]}\"";
      return $gis;
  return false;

Until next time!

Ringmaker 2.0 Final Orca Blog problems

Comments closed