Esempio n. 1
0
 /**
  * Loads an image from $filename
  *
  * @param string $filename
  * @return GDImage
  */
 public static function load($filename)
 {
     if (!file_exists($filename)) {
         throw new Exception('Image file does not exist.');
     }
     if (self::$maxSize && filesize($filename) > self::$maxSize) {
         throw new Exception('Image file is larger than maxSize');
     }
     if (!($file = file_get_contents($filename))) {
         return null;
     }
     if (!($image = GDImage::fromString($file))) {
         return null;
     }
     $image->filename = $filename;
     if (preg_match('/\\.png$/', $filename)) {
         $image->type = 'png';
     } elseif (preg_match('/\\.gif$/', $filename)) {
         $image->type = 'gif';
     } else {
         $image->type = 'jpg';
     }
     return $image;
 }