php-image-resize
php-image-resize copied to clipboard
Is it possible to chain multiply crops on one image?
I am using this library to crop my images dynamically with my image server. The image server allows to pass with, height or both in the url and will scale and drop the picture automatically.
However, I would like the user to be able to crop the original image via a GUI (while keeping the original image on the server) and only apply the user crop while delivering the image. So I came up with the following script. However, as soon as either the outputwidth
or outputheight
is defined and any of the crop
resizeToBestFit
resizeToWidth
or resizeToHeight
is applied, the crop will be overwritten instead of chained. I am not sure if this is the expected behavior (for me it's not) and how to work around this. Any ideas?
$image = new ImageResize($originname);
$image->quality_jpg = 80;
$image->gamma(false);
$allow_enlarge = true;
//First crop to custom user crop
if(isset($crop_x) && isset($crop_y) && isset($crop_width) && isset($crop_height)){
$image->freecrop($crop_width, $crop_height, $crop_x, $crop_y);
}
//Then apply output sizing and auto cropping
if(isset($this->outputwidth) && isset($this->outputheight)){
if($this->outputcrop === true){
$image->crop($this->outputwidth, $this->outputheight, $allow_enlarge);
}else{
$image->resizeToBestFit($this->outputwidth, $this->outputheight, $allow_enlarge);
}
}elseif(isset($this->outputwidth)){
$image->resizeToWidth($this->uniform_srcsize($this->outputwidth), $allow_enlarge);
}elseif(isset($this->outputheight)){
$image->resizeToHeight($this->uniform_srcsize($this->outputheight), $allow_enlarge);
}
$image->save($path."/cache/".$cachename, IMAGETYPE_JPEG);