5 use \Intervention\Image\Point;
6 use \Intervention\Image\Size;
18 $width = $this->
argument(0)->type(
'digit')->required()->value();
19 $height = $this->
argument(1)->type(
'digit')->required()->value();
20 $anchor = $this->
argument(2)->value(
'center');
21 $relative = $this->
argument(3)->type(
'boolean')->value();
22 $bgcolor = $this->
argument(4)->value();
24 $original_width = $image->getWidth();
25 $original_height = $image->getHeight();
28 $width = is_null($width) ? $original_width : intval($width);
29 $height = is_null($height) ? $original_height : intval($height);
33 $width = $original_width + $width;
34 $height = $original_height + $height;
38 $width = ($width <= 0) ? $width + $original_width : $width;
39 $height = ($height <= 0) ? $height + $original_height : $height;
42 $canvas = $image->getDriver()->newImage($width, $height, $bgcolor);
45 $canvas_size = $canvas->getSize()->align($anchor);
46 $image_size = $image->getSize()->align($anchor);
47 $canvas_pos = $image_size->relativePosition($canvas_size);
48 $image_pos = $canvas_size->relativePosition($image_size);
50 if ($width <= $original_width) {
52 $src_x = $canvas_pos->x;
53 $src_w = $canvas_size->width;
55 $dst_x = $image_pos->x;
57 $src_w = $original_width;
60 if ($height <= $original_height) {
62 $src_y = $canvas_pos->y;
63 $src_h = $canvas_size->height;
65 $dst_y = $image_pos->y;
67 $src_h = $original_height;
72 $transparent = imagecolorallocatealpha($canvas->getCore(), 255, 255, 255, 127);
73 imagealphablending($canvas->getCore(),
false);
74 imagefilledrectangle($canvas->getCore(), $dst_x, $dst_y, $dst_x + $src_w - 1, $dst_y + $src_h - 1, $transparent);
77 imagecopy($canvas->getCore(), $image->getCore(), $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);
80 $image->setCore($canvas->getCore());