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

fix upscale size not being calculated correctly #561

Merged
merged 1 commit into from
Jun 4, 2015

Conversation

plandolt
Copy link
Contributor

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.

@@ -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)));
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

…sion.

renamed and better explained

renamed file
@plandolt
Copy link
Contributor Author

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
Copy link
Collaborator

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?

Copy link
Contributor Author

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)

@lsmith77 lsmith77 added the State: Reviewing This item is being reviewed to determine if it should be accepted. label May 29, 2015
makasim added a commit that referenced this pull request Jun 4, 2015
fix upscale size not being calculated correctly
@makasim makasim merged commit 1c9ccde into liip:master Jun 4, 2015
@lsmith77 lsmith77 removed the State: Reviewing This item is being reviewed to determine if it should be accepted. label Jun 4, 2015
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

Successfully merging this pull request may close these issues.

3 participants