Exemple #1
0
 /**
  * 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;
 }
Exemple #2
0
 public function testGdResourceToTruecolor()
 {
     $resource = imagecreate(10, 10);
     $this->assertFalse(imageistruecolor($resource));
     Helper::gdResourceToTruecolor($resource);
     $this->assertTrue(imageistruecolor($resource));
 }