PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.1
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.1
3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 2.8.17 2.8.18 All 259 releases
wpfunnels / vendor / intervention / image / src / Intervention / Image / Imagick / Decoder.php

Decoder.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.1, at vendor/intervention/image/src/Intervention/Image/Imagick/Decoder.php

125 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Intervention\Image\Imagick;
4
5 use Intervention\Image\AbstractDecoder;
6 use Intervention\Image\Exception\NotReadableException;
7 use Intervention\Image\Exception\NotSupportedException;
8 use Intervention\Image\Image;
9
10 class Decoder extends AbstractDecoder
11 {
12 /**
13 * Initiates new image from path in filesystem
14 *
15 * @param string $path
16 * @return \Intervention\Image\Image
17 */
18 public function initFromPath($path)
19 {
20 $core = new \Imagick;
21
22 try {
23
24 $core->setBackgroundColor(new \ImagickPixel('transparent'));
25 $core->readImage($path);
26 $core->setImageType(defined('\Imagick::IMGTYPE_TRUECOLORALPHA') ? \Imagick::IMGTYPE_TRUECOLORALPHA : \Imagick::IMGTYPE_TRUECOLORMATTE);
27
28 } catch (\ImagickException $e) {
29 throw new \Intervention\Image\Exception\NotReadableException(
30 "Unable to read image from path ({$path}).",
31 0,
32 $e
33 );
34 }
35
36 // build image
37 $image = $this->initFromImagick($core);
38 $image->setFileInfoFromPath($path);
39
40 return $image;
41 }
42
43 /**
44 * Initiates new image from GD resource
45 *
46 * @param Resource $resource
47 * @return \Intervention\Image\Image
48 */
49 public function initFromGdResource($resource)
50 {
51 throw new NotSupportedException(
52 'Imagick driver is unable to init from GD resource.'
53 );
54 }
55
56 /**
57 * Initiates new image from Imagick object
58 *
59 * @param Imagick $object
60 * @return \Intervention\Image\Image
61 */
62 public function initFromImagick(\Imagick $object)
63 {
64 // currently animations are not supported
65 // so all images are turned into static
66 $object = $this->removeAnimation($object);
67
68 // reset image orientation
69 $object->setImageOrientation(\Imagick::ORIENTATION_UNDEFINED);
70
71 return new Image(new Driver, $object);
72 }
73
74 /**
75 * Initiates new image from binary data
76 *
77 * @param string $data
78 * @return \Intervention\Image\Image
79 */
80 public function initFromBinary($binary)
81 {
82 $core = new \Imagick;
83
84 try {
85 $core->setBackgroundColor(new \ImagickPixel('transparent'));
86
87 $core->readImageBlob($binary);
88
89 } catch (\ImagickException $e) {
90 throw new NotReadableException(
91 "Unable to read image from binary data.",
92 0,
93 $e
94 );
95 }
96
97 // build image
98 $image = $this->initFromImagick($core);
99 $image->mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $binary);
100
101 return $image;
102 }
103
104 /**
105 * Turns object into one frame Imagick object
106 * by removing all frames except first
107 *
108 * @param Imagick $object
109 * @return Imagick
110 */
111 private function removeAnimation(\Imagick $object)
112 {
113 $imagick = new \Imagick;
114
115 foreach ($object as $frame) {
116 $imagick->addImage($frame->getImage());
117 break;
118 }
119
120 $object->destroy();
121
122 return $imagick;
123 }
124 }
125