Example #1
0
 public function resize($width, $height, $flags = Image::FIT)
 {
     if ($flags & Image::EXACT) {
         return $this->resize($width, $height, Image::FILL | Image::SHRINK_ONLY)->crop('50%', '50%', $width, $height);
     }
     list($newWidth, $newHeight) = Image::calculateSize($this->getWidth(), $this->getHeight(), $width, $height, $flags);
     $this->getImageResource()->resizeImage($newWidth, $newHeight, IMAGICK::FILTER_LANCZOS, 1);
     return $this;
 }
Example #2
0
 public function resize($width, $height, $flags = Image::FIT)
 {
     if ($flags & Image::EXACT) {
         return $this->resize($width, $height, Image::FILL | Image::SHRINK_ONLY)->crop('50%', '50%', $width, $height);
     }
     list($newWidth, $newHeight) = Image::calculateSize($this->getWidth(), $this->getHeight(), $width, $height, $flags);
     if ($newWidth !== $this->getWidth() || $newHeight !== $this->getHeight()) {
         // resize
         $newImage = static::fromBlank($newWidth, $newHeight, Image::RGB(0, 0, 0, 127))->getImageResource();
         imagecopyresampled($newImage, $this->getImageResource(), 0, 0, 0, 0, $newWidth, $newHeight, $this->getWidth(), $this->getHeight());
         $this->image = $newImage;
     }
     if ($width < 0 || $height < 0) {
         // flip is processed in two steps for better quality
         $newImage = static::fromBlank($newWidth, $newHeight, Image::RGB(0, 0, 0, 127))->getImageResource();
         imagecopyresampled($newImage, $this->getImageResource(), 0, 0, $width < 0 ? $newWidth - 1 : 0, $height < 0 ? $newHeight - 1 : 0, $newWidth, $newHeight, $width < 0 ? -$newWidth : $newWidth, $height < 0 ? -$newHeight : $newHeight);
         $this->image = $newImage;
     }
     return $this;
 }