Skip to content

Banding doesn't work correctly. #24

@Masato-Kato

Description

@Masato-Kato

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions