method crop documentation in bbn\File\Image

Returns a crop of the image.

Example

$img = new bbn\File\Image("/home/data/test/image.jpg"); bbn\X::dump($img->getWidth(),$img->getHeight()); // (int) 345 146 $img->crop(10, 10, 30, 30)->save("/home/data/test/img2.jpeg"); $img2 = new \bbn\File\Image("/home/data/test/img2.jpeg"); bbn\X::hdump($img2->getWidth(),$img2->getHeight()); // (int) 10 10 function($w, $h, $x, $y) { if ($this->test()) { $args = \func_get_args(); foreach ($args as $arg){ if (!is_numeric($arg)) { $this->error = X::_("Arguments must be numeric"); } } if ($w + $x > $this->w) { return false; } if ($h + $y > $this->h) { return false; } if (self::isImagick()) { if (!$this->img->cropImage($w,$h,$x,$y)) { $this->error = X::_("There has been a problem"); } } else { $img = imagecreatetruecolor($w,$h); if ($this->ext == 'png' || $this->ext == 'gif' || $this->ext == 'svg') { imagecolorallocatealpha($img, 0, 0, 0, 127); imagealphablending($img, false); imagesavealpha($img, true); } if (imagecopyresampled($img,$this->img,0,0,$x,$y,$w,$h,$w,$h)) { $this->img = $img; } else{ $this->error = X::_("There has been a problem during the resampling"); } } } return $this; }

Returns a crop of the image. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.