Skip to content

Fix issue #188 #189

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

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions lib/ImageResize.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,12 @@ public function resizeToShortSide($max_short, $allow_enlarge = false)
{
if ($this->getSourceHeight() < $this->getSourceWidth()) {
$ratio = $max_short / $this->getSourceHeight();
$long = (int) ($this->getSourceWidth() * $ratio);
$long = (int) round($this->getSourceWidth() * $ratio);

$this->resize($long, $max_short, $allow_enlarge);
} else {
$ratio = $max_short / $this->getSourceWidth();
$long = (int) ($this->getSourceHeight() * $ratio);
$long = (int) round($this->getSourceHeight() * $ratio);

$this->resize($max_short, $long, $allow_enlarge);
}
Expand All @@ -489,12 +489,12 @@ public function resizeToLongSide($max_long, $allow_enlarge = false)
{
if ($this->getSourceHeight() > $this->getSourceWidth()) {
$ratio = $max_long / $this->getSourceHeight();
$short = (int) ($this->getSourceWidth() * $ratio);
$short = (int) round($this->getSourceWidth() * $ratio);

$this->resize($short, $max_long, $allow_enlarge);
} else {
$ratio = $max_long / $this->getSourceWidth();
$short = (int) ($this->getSourceHeight() * $ratio);
$short = (int) round($this->getSourceHeight() * $ratio);

$this->resize($max_long, $short, $allow_enlarge);
}
Expand All @@ -512,7 +512,7 @@ public function resizeToLongSide($max_long, $allow_enlarge = false)
public function resizeToHeight($height, $allow_enlarge = false)
{
$ratio = $height / $this->getSourceHeight();
$width = (int) ($this->getSourceWidth() * $ratio);
$width = (int) round($this->getSourceWidth() * $ratio);

$this->resize($width, $height, $allow_enlarge);

Expand All @@ -529,7 +529,7 @@ public function resizeToHeight($height, $allow_enlarge = false)
public function resizeToWidth($width, $allow_enlarge = false)
{
$ratio = $width / $this->getSourceWidth();
$height = (int) ($this->getSourceHeight() * $ratio);
$height = (int) round($this->getSourceHeight() * $ratio);

$this->resize($width, $height, $allow_enlarge);

Expand All @@ -552,11 +552,11 @@ public function resizeToBestFit($max_width, $max_height, $allow_enlarge = false)

$ratio = $this->getSourceHeight() / $this->getSourceWidth();
$width = $max_width;
$height = (int) ($width * $ratio);
$height = (int) round($width * $ratio);

if ($height > $max_height) {
$height = $max_height;
$width = (int) ($height / $ratio);
$width = (int) round($height / $ratio);
}

return $this->resize($width, $height, $allow_enlarge);
Expand All @@ -570,8 +570,8 @@ public function resizeToBestFit($max_width, $max_height, $allow_enlarge = false)
*/
public function scale($scale)
{
$width = (int) ($this->getSourceWidth() * $scale / 100);
$height = (int) ($this->getSourceHeight() * $scale / 100);
$width = (int) round($this->getSourceWidth() * $scale / 100);
$height = (int) round($this->getSourceHeight() * $scale / 100);

$this->resize($width, $height, true);

Expand Down Expand Up @@ -642,7 +642,7 @@ public function crop($width, $height, $allow_enlarge = false, $position = self::
if ($ratio_dest < $ratio_source) {
$this->resizeToHeight($height, $allow_enlarge);

$excess_width = (int) (($this->getDestWidth() - $width) * $this->getSourceWidth() / $this->getDestWidth());
$excess_width = (int) round(($this->getDestWidth() - $width) * $this->getSourceWidth() / $this->getDestWidth());

$this->source_w = $this->getSourceWidth() - $excess_width;
$this->source_x = $this->getCropPosition($excess_width, $position);
Expand All @@ -651,7 +651,7 @@ public function crop($width, $height, $allow_enlarge = false, $position = self::
} else {
$this->resizeToWidth($width, $allow_enlarge);

$excess_height = (int) (($this->getDestHeight() - $height) * $this->getSourceHeight() / $this->getDestHeight());
$excess_height = (int) round(($this->getDestHeight() - $height) * $this->getSourceHeight() / $this->getDestHeight());

$this->source_h = $this->getSourceHeight() - $excess_height;
$this->source_y = $this->getCropPosition($excess_height, $position);
Expand Down Expand Up @@ -758,7 +758,7 @@ protected function getCropPosition($expectedSize, $position = self::CROPCENTER)
$size = $expectedSize / 4;
break;
}
return (int) $size;
return (int) round($size);
}

/**
Expand Down