mirror of
https://github.com/Intervention/image.git
synced 2025-08-31 17:41:58 +02:00
Incorporate pivot point in CropModifier
This commit is contained in:
@@ -64,12 +64,14 @@ class CropModifier extends SpecializedModifier
|
|||||||
$targetHeight
|
$targetHeight
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// don't alpha blend for covering areas
|
||||||
imagealphablending($modified, false);
|
imagealphablending($modified, false);
|
||||||
|
|
||||||
// cover the possible newly created areas with background color
|
// cover the possible newly created areas with background color
|
||||||
if ($resizeTo->width() > $originalSize->width() || $this->offset_x > 0) {
|
if ($resizeTo->width() > $originalSize->width() || $this->offset_x > 0) {
|
||||||
imagefilledrectangle(
|
imagefilledrectangle(
|
||||||
$modified,
|
$modified,
|
||||||
$originalSize->width() + ($this->offset_x * -1),
|
$originalSize->width() + ($this->offset_x * -1) - $resizeTo->pivot()->x(),
|
||||||
0,
|
0,
|
||||||
$resizeTo->width(),
|
$resizeTo->width(),
|
||||||
$resizeTo->height(),
|
$resizeTo->height(),
|
||||||
@@ -78,37 +80,37 @@ class CropModifier extends SpecializedModifier
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cover the possible newly created areas with background color
|
// 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(
|
imagefilledrectangle(
|
||||||
$modified,
|
$modified,
|
||||||
($this->offset_x * -1),
|
($this->offset_x * -1) - $resizeTo->pivot()->x(),
|
||||||
$originalSize->height() + ($this->offset_y * -1),
|
$originalSize->height() + ($this->offset_y * -1) - $resizeTo->pivot()->y(),
|
||||||
($this->offset_x * -1) + $originalSize->width() - 1,
|
($this->offset_x * -1) + $originalSize->width() - 1 - $resizeTo->pivot()->x(),
|
||||||
$resizeTo->height(),
|
$resizeTo->height(),
|
||||||
$background
|
$background
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cover the possible newly created areas with background color
|
// cover the possible newly created areas with background color
|
||||||
if ($this->offset_x < 0) {
|
if ($this->offset_x < 0 || $resizeTo->pivot()->x() != 0) {
|
||||||
imagefilledrectangle(
|
imagefilledrectangle(
|
||||||
$modified,
|
$modified,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
($this->offset_x * -1) - 1,
|
($this->offset_x * -1) - $resizeTo->pivot()->x() - 1,
|
||||||
$resizeTo->height(),
|
$resizeTo->height(),
|
||||||
$background
|
$background
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cover the possible newly created areas with background color
|
// cover the possible newly created areas with background color
|
||||||
if ($this->offset_y < 0) {
|
if ($this->offset_y < 0 || $resizeTo->pivot()->y() != 0) {
|
||||||
imagefilledrectangle(
|
imagefilledrectangle(
|
||||||
$modified,
|
$modified,
|
||||||
$this->offset_x * -1,
|
($this->offset_x * -1) - $resizeTo->pivot()->x(),
|
||||||
0,
|
0,
|
||||||
($this->offset_x * -1) + $originalSize->width() - 1,
|
($this->offset_x * -1) + $originalSize->width() - $resizeTo->pivot()->x() - 1,
|
||||||
($this->offset_y * -1) - 1,
|
($this->offset_y * -1) - $resizeTo->pivot()->y() - 1,
|
||||||
$background
|
$background
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -46,7 +46,7 @@ class CropModifier extends DriverSpecializedModifier
|
|||||||
// cover the possible newly created areas with background color
|
// cover the possible newly created areas with background color
|
||||||
if ($crop->width() > $originalSize->width() || $this->offset_x > 0) {
|
if ($crop->width() > $originalSize->width() || $this->offset_x > 0) {
|
||||||
$draw->rectangle(
|
$draw->rectangle(
|
||||||
$originalSize->width() + ($this->offset_x * -1),
|
$originalSize->width() + ($this->offset_x * -1) - $crop->pivot()->x(),
|
||||||
0,
|
0,
|
||||||
$crop->width(),
|
$crop->width(),
|
||||||
$crop->height()
|
$crop->height()
|
||||||
@@ -56,30 +56,30 @@ class CropModifier extends DriverSpecializedModifier
|
|||||||
// cover the possible newly created areas with background color
|
// cover the possible newly created areas with background color
|
||||||
if ($crop->height() > $originalSize->height() || $this->offset_y > 0) {
|
if ($crop->height() > $originalSize->height() || $this->offset_y > 0) {
|
||||||
$draw->rectangle(
|
$draw->rectangle(
|
||||||
($this->offset_x * -1),
|
($this->offset_x * -1) - $crop->pivot()->x(),
|
||||||
$originalSize->height() + ($this->offset_y * -1),
|
$originalSize->height() + ($this->offset_y * -1) - $crop->pivot()->y(),
|
||||||
($this->offset_x * -1) + $originalSize->width() - 1,
|
($this->offset_x * -1) + $originalSize->width() - 1 - $crop->pivot()->x(),
|
||||||
$crop->height()
|
$crop->height()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cover the possible newly created areas with background color
|
// 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(
|
$draw->rectangle(
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
($this->offset_x * -1) - 1,
|
($this->offset_x * -1) - $crop->pivot()->x() - 1,
|
||||||
$crop->height()
|
$crop->height()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cover the possible newly created areas with background color
|
// 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(
|
$draw->rectangle(
|
||||||
$this->offset_x * -1,
|
($this->offset_x * -1) - $crop->pivot()->x(),
|
||||||
0,
|
0,
|
||||||
($this->offset_x * -1) + $originalSize->width() - 1,
|
($this->offset_x * -1) + $originalSize->width() - $crop->pivot()->x() - 1,
|
||||||
($this->offset_y * -1) - 1,
|
($this->offset_y * -1) - $crop->pivot()->y() - 1,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user