-
Notifications
You must be signed in to change notification settings - Fork 379
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
fix upscale size not being calculated correctly #561
Conversation
@@ -35,7 +35,7 @@ public function load(ImageInterface $image, array $options = array()) | |||
|
|||
$ratio = $widthRatio > $heightRatio ? $widthRatio : $heightRatio; | |||
|
|||
$filter = new Resize(new Box($origWidth * $ratio, $origHeight * $ratio)); | |||
$filter = new Resize(new Box(round($origWidth * $ratio), round($origHeight * $ratio))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are dealing with pixels this is why we have to round it, did I get right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The problem is that if we just pass the float value to the Box object it will be casted in the Box constructor which will lead to this issue that float(201) become float(200) which is not what i configured in the filter.
307f513
to
89caa47
Compare
…sion. renamed and better explained renamed file
0f5beb5
to
17ebc33
Compare
Did the rename and added an explaination in the class doc-block |
* @covers Liip\ImagineBundle\Imagine\Filter\Loader\UpscaleFilterLoader | ||
* | ||
* Due to int casting in Imagine\Image\Box which can lead to wrong pixel | ||
* numbers ( e.g. float(201) casted to int(200) ). Solved by round the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the phrase float(201) casted to int(200)
does not look correct. float 201 is cast to int 201. there must be a decimal part which we loose. something like: float(200.7) casted to int(200)
.
Could you confirm that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what is really strange. By executing the test on master while var_dump'ing ratio and the arguments passed to the constructor i get the following:
var_dump($ratio, $origHeight * $ratio);
float(4.02)
float(201)
fix upscale size not being calculated correctly
I had trouble to upsize a 50x50 image to 201x201 because of the float to int casting in the Box Class.
$originWidth * $ration produces a float(201). Passing that to the Box constructor which will cast it to int will produce int(200) which is not what i wanted/configured. Rounding them before passing to the Box constructor solves this issue.