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

Banding doesn't work correctly. #24

Open
Masato-Kato opened this issue Aug 6, 2013 · 0 comments
Open

Banding doesn't work correctly. #24

Masato-Kato opened this issue Aug 6, 2013 · 0 comments

Comments

@Masato-Kato
Copy link
Contributor

Banding facility of UploadBehavior::_resize() doesn't work correctly.

For example we have a source image (width: 400px; height: 300px) and going to fit it into [480x270] with UploadPack.

In the banding login in _resize() is following:

if ($srcW > $srcH) $ratio = $destW/$srcW;
else $ratio = $destH/$srcH;
$resizeW = $srcW*$ratio;
$resizeH = $srcH*$ratio;

$srcW = 400, $srcH = 300, $destW = 480, $destH = 270. $srcW (400) > $srcH (300) so $ratio = 480 / 400 = 1.2, $resizeW = 400 * 1.2 = 480, $resizeH = 300 * 1.2 = 360.

However, $resizeH (360) > $destH (270) so destination image will be cropped in top side and bottom side, not banding with while rectangle.

This can be fixed by following code:

$srcRatio = $srcW / $srcH; // >1: landscape;     =1: square;     <1: portrait
$destRatio = $destW / $destH;
if ( $srcRatio > $destRatio )
{
    // source is "flatter" than destination => fit in width
    $resizeW = $destW;
    $resizeH = $resizeW / $srcRatio;
}
else
{
    // source is "taller" than destination => fit in height
    $resizeH = $destH;
    $resizeW = $resizeH * $srcRatio;
}

Hope this helps.

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