Cheetah
Decoder.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use \Intervention\Image\Image;
6 use \Intervention\Image\Size;
7 
9 {
16  public function initFromPath($path)
17  {
18  $core = new \Imagick;
19 
20  try {
21 
22  $core->readImage($path);
23  $core->setImageType(\Imagick::IMGTYPE_TRUECOLORMATTE);
24 
25  } catch (\ImagickException $e) {
26  throw new \Intervention\Image\Exception\NotReadableException(
27  "Unable to read image from path ({$path})."
28  );
29  }
30 
31  // build image
32  $image = $this->initFromImagick($core);
33  $image->setFileInfoFromPath($path);
34 
35  return $image;
36  }
37 
44  public function initFromGdResource($resource)
45  {
46  throw new \Intervention\Image\Exception\NotSupportedException(
47  'Imagick driver is unable to init from GD resource.'
48  );
49  }
50 
57  public function initFromImagick(\Imagick $object)
58  {
59  // currently animations are not supported
60  // so all images are turned into static
61  $object = $this->removeAnimation($object);
62 
63  // reset image orientation
64  $object->setImageOrientation(\Imagick::ORIENTATION_UNDEFINED);
65 
66  return new Image(new Driver, $object);
67  }
68 
75  public function initFromBinary($binary)
76  {
77  $core = new \Imagick;
78 
79  try {
80 
81  $core->readImageBlob($binary);
82 
83  } catch (\ImagickException $e) {
84  throw new \Intervention\Image\Exception\NotReadableException(
85  "Unable to read image from binary data."
86  );
87  }
88 
89  // build image
90  $image = $this->initFromImagick($core);
91  $image->mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $binary);
92 
93  return $image;
94  }
95 
103  private function removeAnimation(\Imagick $object)
104  {
105  $imagick = new \Imagick;
106 
107  foreach ($object as $frame) {
108  $imagick->addImage($frame->getImage());
109  break;
110  }
111 
112  $object->destroy();
113 
114  return $imagick;
115  }
116 }
Intervention\Image\Imagick\Decoder\initFromPath
initFromPath($path)
Definition: Decoder.php:16
Intervention\Image\Imagick
Definition: Color.php:3
Intervention\Image\Imagick\Driver
Definition: Driver.php:8
Intervention\Image\Imagick\Decoder\initFromBinary
initFromBinary($binary)
Definition: Decoder.php:75
php
Intervention\Image\Imagick\Decoder
Definition: Decoder.php:9
Intervention\Image\AbstractDecoder
Definition: AbstractDecoder.php:6
Intervention\Image\Image
Definition: Image.php:50
$path
$path
Definition: header.inc.php:12
Intervention\Image\Imagick\Decoder\initFromImagick
initFromImagick(\Imagick $object)
Definition: Decoder.php:57
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
Intervention\Image\Imagick\Decoder\initFromGdResource
initFromGdResource($resource)
Definition: Decoder.php:44