mirror of
https://github.com/Intervention/image.git
synced 2025-01-17 12:18:14 +01:00
Fix bugs
This commit is contained in:
parent
59a4353661
commit
2fe03aeba7
@ -537,11 +537,16 @@ final class Image implements ImageInterface, Countable
|
||||
return $this->modify(new ResizeCanvasModifier($width, $height, $background, $position));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see ImageInterface::resizeCanvasRelative()
|
||||
*/
|
||||
public function resizeCanvasRelative(
|
||||
?int $width = null,
|
||||
?int $height = null,
|
||||
mixed $background = 'ffffff',
|
||||
string $position = 'center',
|
||||
string $position = 'center'
|
||||
): ImageInterface {
|
||||
return $this->modify(new ResizeCanvasRelativeModifier($width, $height, $background, $position));
|
||||
}
|
||||
|
@ -403,7 +403,7 @@ interface ImageInterface extends IteratorAggregate, Countable
|
||||
int $width,
|
||||
int $height,
|
||||
mixed $background = 'ffffff',
|
||||
string $position = 'center',
|
||||
string $position = 'center'
|
||||
): ImageInterface;
|
||||
|
||||
/**
|
||||
@ -420,7 +420,7 @@ interface ImageInterface extends IteratorAggregate, Countable
|
||||
int $width,
|
||||
int $height,
|
||||
mixed $background = 'ffffff',
|
||||
string $position = 'center',
|
||||
string $position = 'center'
|
||||
): ImageInterface;
|
||||
|
||||
/**
|
||||
@ -440,7 +440,7 @@ interface ImageInterface extends IteratorAggregate, Countable
|
||||
int $height,
|
||||
int $offset_x = 0,
|
||||
int $offset_y = 0,
|
||||
string $position = 'top-left',
|
||||
string $position = 'top-left'
|
||||
): ImageInterface;
|
||||
|
||||
/**
|
||||
|
@ -19,12 +19,28 @@ class ContainModifier extends AbstractModifier
|
||||
public function getCropSize(ImageInterface $image): SizeInterface
|
||||
{
|
||||
return $image->size()
|
||||
->contain($this->width, $this->height)
|
||||
->alignPivotTo($this->getResizeSize($image), $this->position);
|
||||
->contain(
|
||||
$this->width,
|
||||
$this->height
|
||||
)
|
||||
->alignPivotTo(
|
||||
$this->getResizeSize($image),
|
||||
$this->position()
|
||||
);
|
||||
}
|
||||
|
||||
public function getResizeSize(ImageInterface $image): SizeInterface
|
||||
{
|
||||
return new Rectangle($this->width, $this->height);
|
||||
}
|
||||
|
||||
protected function position(): string
|
||||
{
|
||||
return strtr($this->position, [
|
||||
'left' => 'right',
|
||||
'right' => 'left',
|
||||
'top' => 'bottom',
|
||||
'bottom' => 'top',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,13 @@ class PadModifier extends ContainModifier
|
||||
public function getCropSize(ImageInterface $image): SizeInterface
|
||||
{
|
||||
return $image->size()
|
||||
->containMax($this->width, $this->height)
|
||||
->alignPivotTo($this->getResizeSize($image), $this->position);
|
||||
->containMax(
|
||||
$this->width,
|
||||
$this->height
|
||||
)
|
||||
->alignPivotTo(
|
||||
$this->getResizeSize($image),
|
||||
$this->position()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,10 @@ class ResizeCanvasModifier extends AbstractModifier
|
||||
$height = is_null($this->height) ? $image->height() : $this->height;
|
||||
|
||||
return (new Rectangle($width, $height))
|
||||
->alignPivotTo($image->size(), $this->position());
|
||||
->alignPivotTo(
|
||||
$image->size(),
|
||||
$this->position()
|
||||
);
|
||||
}
|
||||
|
||||
protected function position(): string
|
||||
|
@ -14,6 +14,9 @@ class ResizeCanvasRelativeModifier extends ResizeCanvasModifier
|
||||
$height = is_null($this->height) ? $image->height() : $image->height() + $this->height;
|
||||
|
||||
return (new Rectangle($width, $height))
|
||||
->alignPivotTo($image->size(), $this->position());
|
||||
->alignPivotTo(
|
||||
$image->size(),
|
||||
$this->position()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user