mirror of
https://github.com/Intervention/image.git
synced 2025-08-28 08:09:54 +02:00
Display the blending color in GD's CropModifier
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user