Robin S Posted October 19, 2016 Posted October 19, 2016 In the blog post that introduces the $pageimage->maxSize() method, it is described like this: Quote $thumb = $image->maxSize($width, $height); This will return an image no larger than the given dimensions, without cropping or anything that would modify the proportions. Of course, this also means that it's likely one of the dimensions (width or height) will be less than what you asked for, since nothing can be cropped. But when I use maxSize() in PW 3.0.37 I do get a cropped image. I have an image that is 1200x600 and if I do $my_image->maxSize(400,400)->url I get an image that is cropped 400x400 when I think it should be uncropped 400x200. Can anyone confirm? I'm sure this method used to work properly as described. 1
Zeka Posted October 20, 2016 Posted October 20, 2016 Hi @Robin S I can confirm that this method has unexpected behavior. Not sure, but I think that this: public function maxSize($width, $height, $options = array()) { $w = $this->width(); $h = $this->height(); if($w >= $h) { if($w > $width && $h > $height) { return $this->size($width, $height, $options); } else { return $this->maxWidth($width, $options); } } else { if($w > $width && $h > $height) { return $this->size($width, $height, $options); } else { return $this->maxHeight($height, $options); } } } should be public function maxSize($width, $height, $options = array()) { $w = $this->width(); $h = $this->height(); if($w >= $h) { return $this->maxWidth($width, $options); } else { return $this->maxHeight($height, $options); } } 2
horst Posted October 20, 2016 Posted October 20, 2016 <shameless advertisement>I use PIA with $image->contain("size=200"); It respects upscaling and weighten too.</shameless advertisement> 1
Robin S Posted October 20, 2016 Author Posted October 20, 2016 Thanks for the confirmation @Zeka. I have created a Github issue and suggested your fix. The problem can be worked around for now using the size() method with cropping set to false. $my_image->size(400,400, array('cropping' => false)); @horst, the weighten feature in PIA is cool. 4
Zeka Posted October 20, 2016 Posted October 20, 2016 @Robin S Thanks for creating an issue, but I not sure that my fix is covering all cases. Maybe somebody from more experienced members can check it. 1
bernhard Posted June 8, 2017 Posted June 8, 2017 i came across this issue on PW 3.0.63 i did some testing and it seems that this issue is not fixed with @Zeka s solution. it is still not working for squared images! see this tests: i changed the function to @Robin S suggested fix and it works: /** * Return an image no larger than the given width and height * * #pw-group-resize-and-crop * * @param int $width Max allowed width * @param int $height Max allowed height * @param array $options See `Pageimage::size()` method for options * @return Pageimage * */ public function maxSize($width, $height, $options = array()) { $defaults = array( 'upscaling' => false, 'cropping' => false ); $options = array_merge($defaults, $options); return $this->size($width, $height, $options); } works also with smaller images using upscaling => true and cropping => true
EntitySelf Posted December 13, 2017 Posted December 13, 2017 This issue still exists in ProcessWire 3.0.85, right? When I have a 640x640 image and call maxSize(400, 250), it returns a 400x400 pixel image.
Robin S Posted December 13, 2017 Author Posted December 13, 2017 I opened a new GitHub issue for this: https://github.com/processwire/processwire-issues/issues/454 2 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now