43 protected function crop($width, $height, $x = 0, $y = 0)
45 if (!$this->
bypassTest($width, $height, $x, $y)) {
46 $this->image->setImageGravity(\Imagick::GRAVITY_NORTHWEST);
47 $this->image->cropImage($width, $height, $x, $y);
48 $this->image->extentImage($width, $height, 0, 0);
49 $this->image->setImagePage(0, 0, 0, 0);
50 $this->size = [$width, $height];
59 protected function resize($width, $height)
64 if (in_array($this->outputFormat, [
"webp",
"png"]) && $this->inputFormat ==
"png") {
68 if (!$this->
bypassTest($newSize[0], $newSize[1])) {
71 $this->image->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);
72 $this->image->setImageGravity(\Imagick::GRAVITY_CENTER);
73 $this->image->resizeImage($newSize[0], $newSize[1], $filter, $blur);
74 $this->image->setImageExtent($newSize[0], $newSize[1]);
75 $this->size = $newSize;
84 protected function thumb($width, $height)
86 [$width, $height] = $this->
dimensions($width, $height);
93 if ($newSize[1] > $height) {
95 $xOffset = -1 * round(($width - $newSize[0]) / 2);
97 $yOffset = -1 * round(($height - $newSize[1]) / 2);
101 $this->image->resizeImage($newSize[0], $newSize[1], $filter, 1,
true);
102 $this->image->extentImage($width, $height, $xOffset, $yOffset);
103 $this->size = [$newSize[0], $newSize[1]];
112 protected function thumbfill($width, $height, $centerX = 50, $centerY = 50)
114 [$width, $height] = $this->
dimensions($width, $height);
116 if (!$this->
bypassTest($width, $height, $centerX - 50, $centerY - 50)) {
121 if ($newSize[1] < $height) {
123 $xOffset = -1 * round(($width - $newSize[0]) * $centerX);
127 $yOffset = -1 * round(($height - $newSize[1]) * $centerY);
131 $this->image->resizeImage($newSize[0], $newSize[1], $filter, 1,
true);
132 $this->image->extentImage($width, $height, $xOffset, $yOffset);
133 $this->size = [$width, $height];
160 if (in_array($this->outputFormat, [
"webp"]) && $this->inputFormat ==
"png") {
161 $this->image->setImageCompressionQuality(100);
163 $result = $this->image->writeImage($this->output);
165 $this->image->clear();
168 throw new \Depage\Graphics\Exceptions\Exception(
'Could not save output image.');
179 switch ($this->image->getImageOrientation()) {
180 case \Imagick::ORIENTATION_TOPLEFT:
182 case \Imagick::ORIENTATION_TOPRIGHT:
183 $this->image->flopImage();
185 case \Imagick::ORIENTATION_BOTTOMRIGHT:
186 $this->image->rotateImage(
"#000", 180);
188 case \Imagick::ORIENTATION_BOTTOMLEFT:
189 $this->image->flopImage();
190 $this->image->rotateImage(
"#000", 180);
192 case \Imagick::ORIENTATION_LEFTTOP:
193 $this->image->flopImage();
194 $this->image->rotateImage(
"#000", -90);
196 case \Imagick::ORIENTATION_RIGHTTOP:
197 $this->image->rotateImage(
"#000", 90);
199 case \Imagick::ORIENTATION_RIGHTBOTTOM:
200 $this->image->flopImage();
201 $this->image->rotateImage(
"#000", 90);
203 case \Imagick::ORIENTATION_LEFTBOTTOM:
204 $this->image->rotateImage(
"#000", -90);
209 $this->image->setImageOrientation(\Imagick::ORIENTATION_TOPLEFT);
219 if ($this->background[0] ===
'#') {
220 $this->image->setImageBackgroundColor($this->background);
221 } elseif ($this->background ==
'checkerboard') {
223 if ($this->outputFormat ==
'jpg') {
224 $this->image->setImageBackgroundColor(
'#fff');
226 $this->image->setImageBackgroundColor(
'transparent');