Cheetah
ResizeCommand.php
Go to the documentation of this file.
1 <?php
2 
4 
6 {
13  public function execute($image)
14  {
15  $width = $this->argument(0)->value();
16  $height = $this->argument(1)->value();
17  $constraints = $this->argument(2)->type('closure')->value();
18 
19  // resize box
20  $resized = $image->getSize()->resize($width, $height, $constraints);
21 
22  // modify image
23  $this->modify($image, 0, 0, 0, 0, $resized->getWidth(), $resized->getHeight(), $image->getWidth(), $image->getHeight());
24 
25  return true;
26  }
27 
42  protected function modify($image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
43  {
44  // create new image
45  $modified = imagecreatetruecolor($dst_w, $dst_h);
46 
47  // get current image
48  $resource = $image->getCore();
49 
50  // preserve transparency
51  $transIndex = imagecolortransparent($resource);
52 
53  if ($transIndex != -1) {
54  $rgba = imagecolorsforindex($modified, $transIndex);
55  $transColor = imagecolorallocatealpha($modified, $rgba['red'], $rgba['green'], $rgba['blue'], 127);
56  imagefill($modified, 0, 0, $transColor);
57  imagecolortransparent($modified, $transColor);
58  } else {
59  imagealphablending($modified, false);
60  imagesavealpha($modified, true);
61  }
62 
63  // copy content from resource
64  $result = imagecopyresampled(
65  $modified,
66  $resource,
67  $dst_x,
68  $dst_y,
69  $src_x,
70  $src_y,
71  $dst_w,
72  $dst_h,
73  $src_w,
74  $src_h
75  );
76 
77  // set new content as recource
78  $image->setCore($modified);
79 
80  return $result;
81  }
82 }
Intervention\Image\Gd\Commands\ResizeCommand\modify
modify($image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
Definition: ResizeCommand.php:42
Intervention\Image\Gd\Commands
Definition: BackupCommand.php:3
php
Intervention\Image\Gd\Commands\ResizeCommand\execute
execute($image)
Definition: ResizeCommand.php:13
Intervention\Image\Commands\AbstractCommand\argument
argument($key)
Definition: AbstractCommand.php:45
Intervention\Image\Commands\AbstractCommand
Definition: AbstractCommand.php:6
Intervention\Image\Gd\Commands\ResizeCommand
Definition: ResizeCommand.php:6