1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-28 16:19:50 +02:00

Display the blending color in GD's CropModifier

This commit is contained in:
Oliver Vogel
2024-01-07 15:06:55 +01:00
parent 22714182da
commit 6308afbd3e

View File

@@ -17,32 +17,43 @@ class CropModifier extends SpecializedModifier
{
public function apply(ImageInterface $image): ImageInterface
{
$originalSize = $image->size();
$crop = $this->crop($image);
foreach ($image as $frame) {
$this->cropFrame($frame, $crop);
$this->cropFrame($frame, $originalSize, $crop);
}
return $image;
}
protected function cropFrame(FrameInterface $frame, SizeInterface $resizeTo): void
protected function cropFrame(FrameInterface $frame, SizeInterface $originalSize, SizeInterface $resizeTo): void
{
// create new image
$modified = Cloner::cloneEmpty($frame->native(), $resizeTo);
// define offset
$offset_x = ($resizeTo->pivot()->x() + $this->offset_x);
$offset_y = ($resizeTo->pivot()->y() + $this->offset_y);
// define target width & height
$targetWidth = min($resizeTo->width(), $originalSize->width());
$targetHeight = min($resizeTo->height(), $originalSize->height());
$targetWidth = $targetWidth < $originalSize->width() ? $targetWidth + $offset_x : $targetWidth;
$targetHeight = $targetHeight < $originalSize->height() ? $targetHeight + $offset_y : $targetHeight;
// copy content from resource
imagecopyresampled(
$modified,
$frame->native(),
$offset_x * -1,
$offset_y * -1,
0,
0,
$resizeTo->pivot()->x() + $this->offset_x,
$resizeTo->pivot()->y() + $this->offset_y,
$resizeTo->width(),
$resizeTo->height(),
$resizeTo->width(),
$resizeTo->height(),
$targetWidth,
$targetHeight,
$targetWidth,
$targetHeight
);
// set new content as recource