Skip to content

Commit

Permalink
Adjust TextModifier::class
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Jan 12, 2025
1 parent 3928a61 commit 6800c77
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Modifiers/TextModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\TextModifier as GenericTextModifier;
use Jcupitt\Vips\BlendMode;

class TextModifier extends GenericTextModifier implements SpecializedInterface
{
Expand All @@ -23,11 +24,26 @@ public function apply(ImageInterface $image): ImageInterface
$lines = $fontProcessor->textBlock($this->text, $this->font, $this->position);

foreach ($lines as $line) {
// build vips image from text
$text = $fontProcessor->textToVipsImage((string) $line, $this->font, $color);

// original line height from vips image
$height = $text->height;

// apply rotation
$text = match ($this->font->angle()) {
0 => $text,
90.0, -270.0 => $text->rot90(),
180.0, -180.0 => $text->rot180(),
-90.0, 270.0 => $text->rot270(),
default => $text->similarity(['angle' => $this->font->angle()]),
};

// place line on image
$image->core()->setNative(
$image->core()->native()->composite($text, 'over', [
$image->core()->native()->composite($text, BlendMode::OVER, [
'x' => $line->position()->x(),
'y' => $line->position()->y(),
'y' => $line->position()->y() - $height,
])
);
}
Expand Down

0 comments on commit 6800c77

Please sign in to comment.