1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-30 09:10:21 +02:00

Incorporate pivot point in CropModifier

This commit is contained in:
Oliver Vogel
2024-01-09 09:32:54 +01:00
parent d2f6b14007
commit 2d2843c37f
2 changed files with 23 additions and 21 deletions

View File

@@ -64,12 +64,14 @@ class CropModifier extends SpecializedModifier
$targetHeight
);
// don't alpha blend for covering areas
imagealphablending($modified, false);
// cover the possible newly created areas with background color
if ($resizeTo->width() > $originalSize->width() || $this->offset_x > 0) {
imagefilledrectangle(
$modified,
$originalSize->width() + ($this->offset_x * -1),
$originalSize->width() + ($this->offset_x * -1) - $resizeTo->pivot()->x(),
0,
$resizeTo->width(),
$resizeTo->height(),
@@ -78,37 +80,37 @@ class CropModifier extends SpecializedModifier
}
// cover the possible newly created areas with background color
if ($resizeTo->width() > $originalSize->height() || $this->offset_y > 0) {
if ($resizeTo->height() > $originalSize->height() || $this->offset_y > 0) {
imagefilledrectangle(
$modified,
($this->offset_x * -1),
$originalSize->height() + ($this->offset_y * -1),
($this->offset_x * -1) + $originalSize->width() - 1,
($this->offset_x * -1) - $resizeTo->pivot()->x(),
$originalSize->height() + ($this->offset_y * -1) - $resizeTo->pivot()->y(),
($this->offset_x * -1) + $originalSize->width() - 1 - $resizeTo->pivot()->x(),
$resizeTo->height(),
$background
);
}
// cover the possible newly created areas with background color
if ($this->offset_x < 0) {
if ($this->offset_x < 0 || $resizeTo->pivot()->x() != 0) {
imagefilledrectangle(
$modified,
0,
0,
($this->offset_x * -1) - 1,
($this->offset_x * -1) - $resizeTo->pivot()->x() - 1,
$resizeTo->height(),
$background
);
}
// cover the possible newly created areas with background color
if ($this->offset_y < 0) {
if ($this->offset_y < 0 || $resizeTo->pivot()->y() != 0) {
imagefilledrectangle(
$modified,
$this->offset_x * -1,
($this->offset_x * -1) - $resizeTo->pivot()->x(),
0,
($this->offset_x * -1) + $originalSize->width() - 1,
($this->offset_y * -1) - 1,
($this->offset_x * -1) + $originalSize->width() - $resizeTo->pivot()->x() - 1,
($this->offset_y * -1) - $resizeTo->pivot()->y() - 1,
$background
);
}

View File

@@ -46,7 +46,7 @@ class CropModifier extends DriverSpecializedModifier
// cover the possible newly created areas with background color
if ($crop->width() > $originalSize->width() || $this->offset_x > 0) {
$draw->rectangle(
$originalSize->width() + ($this->offset_x * -1),
$originalSize->width() + ($this->offset_x * -1) - $crop->pivot()->x(),
0,
$crop->width(),
$crop->height()
@@ -56,30 +56,30 @@ class CropModifier extends DriverSpecializedModifier
// cover the possible newly created areas with background color
if ($crop->height() > $originalSize->height() || $this->offset_y > 0) {
$draw->rectangle(
($this->offset_x * -1),
$originalSize->height() + ($this->offset_y * -1),
($this->offset_x * -1) + $originalSize->width() - 1,
($this->offset_x * -1) - $crop->pivot()->x(),
$originalSize->height() + ($this->offset_y * -1) - $crop->pivot()->y(),
($this->offset_x * -1) + $originalSize->width() - 1 - $crop->pivot()->x(),
$crop->height()
);
}
// cover the possible newly created areas with background color
if ($this->offset_x < 0) {
if ($this->offset_x < 0 || $crop->pivot()->x() != 0) {
$draw->rectangle(
0,
0,
($this->offset_x * -1) - 1,
($this->offset_x * -1) - $crop->pivot()->x() - 1,
$crop->height()
);
}
// cover the possible newly created areas with background color
if ($this->offset_y < 0) {
if ($this->offset_y < 0 || $crop->pivot()->y() != 0) {
$draw->rectangle(
$this->offset_x * -1,
($this->offset_x * -1) - $crop->pivot()->x(),
0,
($this->offset_x * -1) + $originalSize->width() - 1,
($this->offset_y * -1) - 1,
($this->offset_x * -1) + $originalSize->width() - $crop->pivot()->x() - 1,
($this->offset_y * -1) - $crop->pivot()->y() - 1,
);
}