Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to chain multiply crops on one image? #193

Open
nikischin opened this issue Nov 15, 2023 · 0 comments
Open

Is it possible to chain multiply crops on one image? #193

nikischin opened this issue Nov 15, 2023 · 0 comments

Comments

@nikischin
Copy link

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant