Esempio n. 1
0
 /**
  * Creates an ImageResource from a file.
  *
  * @param string $file A filepath
  *
  * @return ImageResource
  */
 public static function createFromFile($file)
 {
     $info = Image\Info::createFromFile($file);
     switch ($info->getType()->getId()) {
         case IMAGETYPE_BMP:
             $resource = imagecreatefromwbmp($file);
             break;
         case IMAGETYPE_GIF:
             $resource = imagecreatefromgif($file);
             break;
         case IMAGETYPE_JPEG:
             $resource = imagecreatefromjpeg($file);
             break;
         case IMAGETYPE_PNG:
             $resource = imagecreatefrompng($file);
             break;
         default:
             throw new InvalidArgumentException('Unknown image file');
     }
     return new static($resource, null, $info);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function getImageInfo($path)
 {
     $location = $this->applyPathPrefix($path);
     return Image\Info::createFromFile($location);
 }
Esempio n. 3
0
 public function testCreateFromFileFail()
 {
     $this->setExpectedException(IOException::class, 'Failed to get image data from file');
     Image\Info::createFromFile('drop-bear.jpg');
 }