1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-27 15:50:09 +02:00

Add methods

This commit is contained in:
Oliver Vogel
2023-11-26 10:56:30 +01:00
parent 60f2bed543
commit 54c9518fc1
3 changed files with 19 additions and 3 deletions

View File

@@ -29,7 +29,7 @@ class TextModifier extends AbstractTextModifier
foreach ($lines as $line) {
imagettftext(
$frame->native(),
$this->adjustedSize(),
$this->adjustedFontSize(),
$this->font->angle() * -1,
$line->position()->x(),
$line->position()->y(),
@@ -75,7 +75,7 @@ class TextModifier extends AbstractTextModifier
// calculate box size from font file with angle 0
$box = imageftbbox(
$this->adjustedSize(),
$this->adjustedFontSize(),
0,
$this->font->filename(),
$text
@@ -91,7 +91,7 @@ class TextModifier extends AbstractTextModifier
return $polygon;
}
private function adjustedSize(): float
private function adjustedFontSize(): float
{
return floatval(ceil($this->font->size() * .75));
}

View File

@@ -26,6 +26,8 @@ use Intervention\Image\Interfaces\ModifierInterface;
use Intervention\Image\Interfaces\ProfileInterface;
use Intervention\Image\Interfaces\ResolutionInterface;
use Intervention\Image\Interfaces\SizeInterface;
use Intervention\Image\Modifiers\GreyscaleModifier;
use Intervention\Image\Modifiers\PixelateModifier;
use Intervention\Image\Modifiers\SharpenModifier;
use Intervention\Image\Modifiers\TextModifier;
use Intervention\Image\Typography\FontFactory;
@@ -134,6 +136,16 @@ class Image implements ImageInterface, Countable
return $this->modify(new SharpenModifier($amount));
}
public function pixelate(int $size): ImageInterface
{
return $this->modify(new PixelateModifier($size));
}
public function greyscale(): ImageInterface
{
return $this->modify(new GreyscaleModifier());
}
public function text(string $text, int $x, int $y, callable|FontInterface $font): ImageInterface
{
return $this->modify(

View File

@@ -19,9 +19,13 @@ interface ImageInterface extends IteratorAggregate, Countable
public function isAnimated(): bool;
public function loops(): int;
public function exif(?string $query = null): mixed;
public function resolution(): ResolutionInterface;
public function colorspace(): ColorspaceInterface;
public function pickColor(int $x, int $y, int $frame_key = 0): ColorInterface;
public function pickColors(int $x, int $y): CollectionInterface;
public function profile(): ProfileInterface;
public function sharpen(int $amount = 10): ImageInterface;
public function greyscale(): ImageInterface;
public function pixelate(int $size): ImageInterface;
public function text(string $text, int $x, int $y, callable|FontInterface $font): ImageInterface;
}