5 use \Intervention\Image\Imagick\Color;
17 $base = $this->
argument(0)->type(
'string')->value();
19 $tolerance = $this->
argument(2)->type(
'numeric')->value(0);
20 $feather = $this->
argument(3)->type(
'numeric')->value(0);
22 $width = $image->getWidth();
23 $height = $image->getHeight();
25 $checkTransparency =
false;
29 $away = array(
'top',
'right',
'bottom',
'left');
30 } elseif (is_string($away)) {
35 foreach ($away
as $key => $value) {
36 $away[$key] = strtolower($value);
40 switch (strtolower($base)) {
43 $checkTransparency =
true;
51 $base_y = $height - 1;
63 if ($checkTransparency) {
64 $base_color =
new Color;
66 $base_color = $image->pickColor($base_x, $base_y,
'object');
70 $trimed = clone $image->getCore();
73 $trimed->borderImage($base_color->getPixel(), 1, 1);
76 $trimed->trimImage(65850 / 100 * $tolerance);
79 $imagePage = $trimed->getImagePage();
80 list($crop_x, $crop_y) = array($imagePage[
'x']-1, $imagePage[
'y']-1);
82 list($crop_width, $crop_height) = array($trimed->width, $trimed->height);
85 if ( ! in_array(
'right', $away)) {
86 $crop_width = $crop_width + ($width - ($width - $crop_x));
90 if ( ! in_array(
'bottom', $away)) {
91 $crop_height = $crop_height + ($height - ($height - $crop_y));
95 if ( ! in_array(
'left', $away)) {
96 $crop_width = $crop_width + $crop_x;
101 if ( ! in_array(
'top', $away)) {
102 $crop_height = $crop_height + $crop_y;
107 $crop_width = min($width, ($crop_width + $feather * 2));
108 $crop_height = min($height, ($crop_height + $feather * 2));
109 $crop_x = max(0, ($crop_x - $feather));
110 $crop_y = max(0, ($crop_y - $feather));
113 $image->getCore()->cropImage($crop_width, $crop_height, $crop_x, $crop_y);
114 $image->getCore()->setImagePage(0,0,0,0);