GreyWyvern.com

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;
    fclose($handle);

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

Until next time!

Ringmaker 2.0 Final Orca Blog problems

Comments closed

Recent posts

  1. Iguana no Musume / Iguana Girl Aug 2016
  2. What I'd Like To See In The Elder Scrolls VI - Part 2 Aug 2015
  3. What I'd Like To See In The Elder Scrolls VI Jul 2015
  4. Cyprus, and what capitalists want Mar 2013
  5. Let interest rates on housing rise Sep 2012
  6. Archive

Items of Interest

Webcomics Reading List

Good Eats

Twitter RSS 2.0 Valid XHTML 1.0! Copyright © 2017 Brian Huisman AKA GreyWyvern
ContactSite mapSearch