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.
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:
$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.