Пример #1
0
 /**
  * (non-PHPdoc)
  * @param Image $image
  * @see \Image\Filter\ImageFilterInterface::filter()
  */
 public function filter(Image $image)
 {
     $width = $this->getWidth();
     $height = $this->getHeight();
     $tempimage = imagecreatetruecolor($width, $height);
     if (!imagecopyresampled($tempimage, $image->getSource(), 0, 0, 0, 0, $width, $height, $image->getWidth(), $image->getHeight())) {
         return false;
     }
     imagedestroy($image->getSource());
     $image->setSource($tempimage);
     $image->setWidth($width);
     $image->setHeight($height);
     return true;
 }
Пример #2
0
 /**
  *
  * @param Image $image
  * @see \Image\Filter\Resize::filter()
  */
 public function filter(Image $image)
 {
     $aspect = $image->getHeight() / $this->getWidth();
     if (empty($this->getHeight())) {
         $this->setHeight($this->getWidth() / $aspect);
     }
     if (empty($this->getWidth())) {
         $this->setWidth($this->getHeight() * $aspect);
     }
     $tempimage = imagecreatetruecolor($this->getWidth(), $this->getHeight());
     if (!imagecopyresampled($tempimage, $image->getSource(), 0, 0, $this->getOffsetX(), $this->getOffsetY(), $this->getWidth(), $this->getHeight(), $this->getWidth(), $this->getHeight())) {
         return false;
     }
     imagedestroy($image->getSource());
     $image->setSource($tempimage);
     $image->setWidth($this->getWidth());
     $image->setHeight($this->getHeight());
     return true;
 }