mirror of
https://github.com/Intervention/image.git
synced 2025-08-13 09:24:05 +02:00
Fix bugs
This commit is contained in:
@@ -537,11 +537,16 @@ final class Image implements ImageInterface, Countable
|
|||||||
return $this->modify(new ResizeCanvasModifier($width, $height, $background, $position));
|
return $this->modify(new ResizeCanvasModifier($width, $height, $background, $position));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @see ImageInterface::resizeCanvasRelative()
|
||||||
|
*/
|
||||||
public function resizeCanvasRelative(
|
public function resizeCanvasRelative(
|
||||||
?int $width = null,
|
?int $width = null,
|
||||||
?int $height = null,
|
?int $height = null,
|
||||||
mixed $background = 'ffffff',
|
mixed $background = 'ffffff',
|
||||||
string $position = 'center',
|
string $position = 'center'
|
||||||
): ImageInterface {
|
): ImageInterface {
|
||||||
return $this->modify(new ResizeCanvasRelativeModifier($width, $height, $background, $position));
|
return $this->modify(new ResizeCanvasRelativeModifier($width, $height, $background, $position));
|
||||||
}
|
}
|
||||||
|
@@ -403,7 +403,7 @@ interface ImageInterface extends IteratorAggregate, Countable
|
|||||||
int $width,
|
int $width,
|
||||||
int $height,
|
int $height,
|
||||||
mixed $background = 'ffffff',
|
mixed $background = 'ffffff',
|
||||||
string $position = 'center',
|
string $position = 'center'
|
||||||
): ImageInterface;
|
): ImageInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -420,7 +420,7 @@ interface ImageInterface extends IteratorAggregate, Countable
|
|||||||
int $width,
|
int $width,
|
||||||
int $height,
|
int $height,
|
||||||
mixed $background = 'ffffff',
|
mixed $background = 'ffffff',
|
||||||
string $position = 'center',
|
string $position = 'center'
|
||||||
): ImageInterface;
|
): ImageInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -440,7 +440,7 @@ interface ImageInterface extends IteratorAggregate, Countable
|
|||||||
int $height,
|
int $height,
|
||||||
int $offset_x = 0,
|
int $offset_x = 0,
|
||||||
int $offset_y = 0,
|
int $offset_y = 0,
|
||||||
string $position = 'top-left',
|
string $position = 'top-left'
|
||||||
): ImageInterface;
|
): ImageInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -19,12 +19,28 @@ class ContainModifier extends AbstractModifier
|
|||||||
public function getCropSize(ImageInterface $image): SizeInterface
|
public function getCropSize(ImageInterface $image): SizeInterface
|
||||||
{
|
{
|
||||||
return $image->size()
|
return $image->size()
|
||||||
->contain($this->width, $this->height)
|
->contain(
|
||||||
->alignPivotTo($this->getResizeSize($image), $this->position);
|
$this->width,
|
||||||
|
$this->height
|
||||||
|
)
|
||||||
|
->alignPivotTo(
|
||||||
|
$this->getResizeSize($image),
|
||||||
|
$this->position()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getResizeSize(ImageInterface $image): SizeInterface
|
public function getResizeSize(ImageInterface $image): SizeInterface
|
||||||
{
|
{
|
||||||
return new Rectangle($this->width, $this->height);
|
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
|
public function getCropSize(ImageInterface $image): SizeInterface
|
||||||
{
|
{
|
||||||
return $image->size()
|
return $image->size()
|
||||||
->containMax($this->width, $this->height)
|
->containMax(
|
||||||
->alignPivotTo($this->getResizeSize($image), $this->position);
|
$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;
|
$height = is_null($this->height) ? $image->height() : $this->height;
|
||||||
|
|
||||||
return (new Rectangle($width, $height))
|
return (new Rectangle($width, $height))
|
||||||
->alignPivotTo($image->size(), $this->position());
|
->alignPivotTo(
|
||||||
|
$image->size(),
|
||||||
|
$this->position()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function position(): string
|
protected function position(): string
|
||||||
|
@@ -14,6 +14,9 @@ class ResizeCanvasRelativeModifier extends ResizeCanvasModifier
|
|||||||
$height = is_null($this->height) ? $image->height() : $image->height() + $this->height;
|
$height = is_null($this->height) ? $image->height() : $image->height() + $this->height;
|
||||||
|
|
||||||
return (new Rectangle($width, $height))
|
return (new Rectangle($width, $height))
|
||||||
->alignPivotTo($image->size(), $this->position());
|
->alignPivotTo(
|
||||||
|
$image->size(),
|
||||||
|
$this->position()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user