Skip to content

Commit cac2723

Browse files
author
irishdan
committed
Add exception for handling intervention issues
1 parent 3814dec commit cac2723

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace IrishDan\ResponsiveImageBundle\Exception;
4+
5+
class ImageProcessingException extends \Exception
6+
{
7+
}

ImageProcessing/ImageStyler.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ImageStyler
3636
*/
3737
private $focusCoordinates = [];
3838
/**
39-
* @var
39+
* @var \Intervention\Image\Image
4040
*/
4141
private $image;
4242
/**
@@ -71,8 +71,8 @@ public function __construct($responsiveImageConfig = [])
7171
public function setCoordinateGroups($cropFocusCoords)
7272
{
7373
// x1, y1, x2, y2:x3, y3, x4, y4
74-
$coordsSets = explode(':', $cropFocusCoords);
75-
$this->cropCoordinates = explode(', ', $coordsSets[0]);
74+
$coordsSets = explode(':', $cropFocusCoords);
75+
$this->cropCoordinates = explode(', ', $coordsSets[0]);
7676
$this->focusCoordinates = explode(', ', $coordsSets[1]);
7777
}
7878

@@ -83,9 +83,9 @@ public function setCoordinateGroups($cropFocusCoords)
8383
*/
8484
public function setStyleData($style = [])
8585
{
86-
$this->styleData['effect'] = empty($style['effect']) ? null : $style['effect'];
87-
$this->styleData['width'] = empty($style['width']) ? null : $style['width'];
88-
$this->styleData['height'] = empty($style['height']) ? null : $style['height'];
86+
$this->styleData['effect'] = empty($style['effect']) ? null : $style['effect'];
87+
$this->styleData['width'] = empty($style['width']) ? null : $style['width'];
88+
$this->styleData['height'] = empty($style['height']) ? null : $style['height'];
8989
$this->styleData['greyscale'] = empty($style['greyscale']) ? null : $style['greyscale'];
9090
}
9191

@@ -123,7 +123,7 @@ protected function setImage($source, $driver = 'gd')
123123
* @param $source
124124
* @param $destination
125125
* @param array $style
126-
* @param null $cropFocusCoords
126+
* @param null $cropFocusCoords
127127
*
128128
* @return string
129129
*/
@@ -202,12 +202,16 @@ function ($constraint) {
202202
*/
203203
protected function cropImage($width, $height, $xOffset, $yOffset)
204204
{
205-
$this->image->crop(
206-
round($width),
207-
round($height),
208-
round($xOffset),
209-
round($yOffset)
210-
);
205+
try {
206+
$this->image->crop(
207+
round($width),
208+
round($height),
209+
round($xOffset),
210+
round($yOffset)
211+
);
212+
} catch (Exception $exception) {
213+
throw new ImageProcessingException($e->getMessage);
214+
}
211215
}
212216

213217
/**
@@ -221,11 +225,11 @@ protected function doCropRectangle()
221225
$geometry = new CoordinateGeometry($cropCoords[0], $cropCoords[1], $cropCoords[2], $cropCoords[3]);
222226

223227
// Get the lengths.
224-
$newWidth = $geometry->axisLength('x');
228+
$newWidth = $geometry->axisLength('x');
225229
$newHeight = $geometry->axisLength('y');
226230

227231
// Do the initial crop.
228-
$this->image->crop($newWidth, $newHeight, $cropCoords[0], $cropCoords[1]);
232+
$this->cropImage($newWidth, $newHeight, $cropCoords[0], $cropCoords[1]);
229233
}
230234
}
231235

@@ -237,7 +241,7 @@ protected function doCropRectangle()
237241
protected function getCoordinates($type = 'crop')
238242
{
239243
$coords = $this->{$type . 'Coordinates'};
240-
$valid = 0;
244+
$valid = 0;
241245
foreach ($coords as $id => $coord) {
242246
if ($coord > 0) {
243247
$valid++;

0 commit comments

Comments
 (0)