Esempio n. 1
0
 /**
  * @covers Cradle\Image\ImageException::forInvalidImageFile
  */
 public function testForInvalidImageFile()
 {
     $message = null;
     try {
         throw ImageException::forInvalidImageFile('foobar');
     } catch (ImageException $e) {
         $message = $e->getMessage();
     }
     $this->assertEquals('foobar is not a valid image file.', $message);
 }
Esempio n. 2
0
 /**
  * Returns the GD image resource
  *
  * @param *string $data The raw image data
  * @param *string $path Whether if this raw data is a file path
  *
  * @return [RESOURCE]
  */
 protected function createResource($data, $path)
 {
     //if the GD Library is not installed
     if (!function_exists('gd_info')) {
         //throw error
         throw ImageException::forGDNotInstalled();
     }
     # imagecreatefromgd — Create a new image from GD file or URL
     # imagecreatefromgif — Create a new image from file or URL
     # imagecreatefromjpeg — Create a new image from file or URL
     # imagecreatefrompng — Create a new image from file or URL
     # imagecreatefromstring — Create a new image from the image stream in the string
     # imagecreatefromwbmp — Create a new image from file or URL
     # imagecreatefromxbm — Create a new image from file or URL
     # imagecreatefromxpm — Create a new image from file or URL
     $resource = false;
     if (!$path) {
         return imagecreatefromstring($data);
     }
     //depending on the extension lets load
     //the file using the right GD loader
     switch ($this->type) {
         case 'gd':
             $resource = imagecreatefromgd($data);
             break;
         case 'gif':
             $resource = imagecreatefromgif($data);
             break;
         case 'jpg':
         case 'jpeg':
         case 'pjpeg':
             $resource = imagecreatefromjpeg($data);
             break;
         case 'png':
             $resource = imagecreatefrompng($data);
             break;
         case 'bmp':
         case 'wbmp':
             $resource = imagecreatefromwbmp($data);
             break;
         case 'xbm':
             $resource = imagecreatefromxbm($data);
             break;
         case 'xpm':
             $resource = imagecreatefromxpm($data);
             break;
     }
     //if there is no resource still
     if (!$resource) {
         //throw error
         ImageException::forInvalidImageFile($path);
     }
     return $resource;
 }