예제 #1
0
파일: Decoder.php 프로젝트: EdgarPost/image
 /**
  * Initiates new image from path in filesystem
  *
  * @param  string $path
  * @return \Intervention\Image\Image
  */
 public function initFromPath($path)
 {
     $info = @getimagesize($path);
     if ($info === false) {
         throw new \Intervention\Image\Exception\NotReadableException("Unable to read image from file ({$path}).");
     }
     // try to decode animated gif
     if ($info['mime'] == 'image/gif') {
         return $this->initFromBinary(file_get_contents($path));
     } else {
         // define core
         switch ($info[2]) {
             case IMAGETYPE_PNG:
                 $core = imagecreatefrompng($path);
                 Helper::gdResourceToTruecolor($core);
                 break;
             case IMAGETYPE_JPEG:
                 $core = imagecreatefromjpeg($path);
                 Helper::gdResourceToTruecolor($core);
                 break;
             case IMAGETYPE_GIF:
                 $core = imagecreatefromgif($path);
                 Helper::gdResourceToTruecolor($core);
                 break;
             default:
                 throw new \Intervention\Image\Exception\NotReadableException("Unable to read image type. GD driver is only able to decode JPG, PNG or GIF files.");
         }
         // build image
         $image = $this->initFromGdResource($core);
     }
     $image->mime = $info['mime'];
     $image->setFileInfoFromPath($path);
     return $image;
 }
예제 #2
0
 public static function initFromDecoded(Decoded $decoded)
 {
     $container = new self();
     $container->setLoops($decoded->getLoops());
     // create empty canvas
     $driver = new Driver();
     $canvas = $driver->newImage($decoded->getCanvasWidth(), $decoded->getCanvasHeight())->getCore();
     foreach ($decoded->getFrames() as $key => $frame) {
         // create resource from frame
         $encoder = new GifEncoder();
         $encoder->setFromDecoded($decoded, $key);
         $frame_resource = imagecreatefromstring($encoder->encode());
         // insert frame image data into canvas
         imagecopy($canvas, $frame_resource, $frame->getOffset()->left, $frame->getOffset()->top, 0, 0, $frame->getSize()->width, $frame->getSize()->height);
         // destory frame resource
         imagedestroy($frame_resource);
         // add frame to container
         $container->addFrame(new \Intervention\Image\Frame($canvas, $frame->getDelay()));
         // prepare next canvas
         $canvas = Helper::cloneResource($canvas);
     }
     return $container;
 }
예제 #3
0
 public function testCloneResource()
 {
     $resource = imagecreate(10, 10);
     $clone = Helper::cloneResource($resource);
     $this->assertNotEquals($resource, $clone);
 }