mirror of
https://github.com/Intervention/image.git
synced 2025-08-29 00:29:55 +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
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
|
$originalSize = $image->size();
|
||||||
$crop = $this->crop($image);
|
$crop = $this->crop($image);
|
||||||
|
|
||||||
foreach ($image as $frame) {
|
foreach ($image as $frame) {
|
||||||
$this->cropFrame($frame, $crop);
|
$this->cropFrame($frame, $originalSize, $crop);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function cropFrame(FrameInterface $frame, SizeInterface $resizeTo): void
|
protected function cropFrame(FrameInterface $frame, SizeInterface $originalSize, SizeInterface $resizeTo): void
|
||||||
{
|
{
|
||||||
// create new image
|
// create new image
|
||||||
$modified = Cloner::cloneEmpty($frame->native(), $resizeTo);
|
$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
|
// copy content from resource
|
||||||
imagecopyresampled(
|
imagecopyresampled(
|
||||||
$modified,
|
$modified,
|
||||||
$frame->native(),
|
$frame->native(),
|
||||||
|
$offset_x * -1,
|
||||||
|
$offset_y * -1,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
$resizeTo->pivot()->x() + $this->offset_x,
|
$targetWidth,
|
||||||
$resizeTo->pivot()->y() + $this->offset_y,
|
$targetHeight,
|
||||||
$resizeTo->width(),
|
$targetWidth,
|
||||||
$resizeTo->height(),
|
$targetHeight
|
||||||
$resizeTo->width(),
|
|
||||||
$resizeTo->height(),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// set new content as recource
|
// set new content as recource
|
||||||
|
Reference in New Issue
Block a user