-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,14 @@ | |
|
||
namespace Intervention\Image\Drivers\Vips\Modifiers; | ||
|
||
use Intervention\Image\Drivers\Vips\Core; | ||
use Intervention\Image\Drivers\Vips\FontProcessor; | ||
use Intervention\Image\Interfaces\FrameInterface; | ||
use Intervention\Image\Interfaces\ImageInterface; | ||
use Intervention\Image\Interfaces\SpecializedInterface; | ||
use Intervention\Image\Modifiers\TextModifier as GenericTextModifier; | ||
use Jcupitt\Vips\BlendMode; | ||
use Jcupitt\Vips\Image as VipsImage; | ||
|
||
class TextModifier extends GenericTextModifier implements SpecializedInterface | ||
{ | ||
|
@@ -39,15 +42,40 @@ public function apply(ImageInterface $image): ImageInterface | |
default => $text->similarity(['angle' => $this->font->angle()]), | ||
}; | ||
|
||
// place line on image | ||
$image->core()->setNative( | ||
$image->core()->native()->composite($text, BlendMode::OVER, [ | ||
'x' => $line->position()->x(), | ||
'y' => $line->position()->y() - $height, | ||
]) | ||
); | ||
if (!$image->isAnimated()) { | ||
// place line on image | ||
$modified = $this->placeTextOnFrame( | ||
$text, | ||
$image->core()->first(), | ||
$line->position()->x(), | ||
$line->position()->y() - $height, | ||
)->native(); | ||
} else { | ||
$frames = []; | ||
foreach ($image as $frame) { | ||
$frames[] = $this->placeTextOnFrame( | ||
$text, | ||
$frame, | ||
$line->position()->x(), | ||
$line->position()->y() - $height, | ||
); | ||
} | ||
|
||
$modified = Core::replaceFrames($image->core()->native(), $frames); | ||
Check failure on line 64 in src/Modifiers/TextModifier.php GitHub Actions / PHP 8.3 - prefer-stable
Check failure on line 64 in src/Modifiers/TextModifier.php GitHub Actions / PHP 8.2 - prefer-stable
Check failure on line 64 in src/Modifiers/TextModifier.php GitHub Actions / PHP 8.1 - prefer-stable
Check failure on line 64 in src/Modifiers/TextModifier.php GitHub Actions / PHP 8.1 - prefer-stable
Check failure on line 64 in src/Modifiers/TextModifier.php GitHub Actions / PHP 8.3 - prefer-stable
Check failure on line 64 in src/Modifiers/TextModifier.php GitHub Actions / PHP 8.4 - prefer-stable
Check failure on line 64 in src/Modifiers/TextModifier.php GitHub Actions / PHP 8.4 - prefer-stable
Check failure on line 64 in src/Modifiers/TextModifier.php GitHub Actions / PHP 8.2 - prefer-stable
|
||
} | ||
} | ||
|
||
$image->core()->setNative($modified); | ||
Check failure on line 68 in src/Modifiers/TextModifier.php GitHub Actions / PHP 8.3 - prefer-stable
Check failure on line 68 in src/Modifiers/TextModifier.php GitHub Actions / PHP 8.2 - prefer-stable
Check failure on line 68 in src/Modifiers/TextModifier.php GitHub Actions / PHP 8.1 - prefer-stable
Check failure on line 68 in src/Modifiers/TextModifier.php GitHub Actions / PHP 8.1 - prefer-stable
Check failure on line 68 in src/Modifiers/TextModifier.php GitHub Actions / PHP 8.3 - prefer-stable
Check failure on line 68 in src/Modifiers/TextModifier.php GitHub Actions / PHP 8.4 - prefer-stable
Check failure on line 68 in src/Modifiers/TextModifier.php GitHub Actions / PHP 8.4 - prefer-stable
|
||
|
||
return $image; | ||
} | ||
|
||
private function placeTextOnFrame(VipsImage $text, FrameInterface $frame, int $x, int $y): FrameInterface | ||
{ | ||
$frame->setNative( | ||
$frame->native()->composite($text, BlendMode::OVER, ['x' => $x, 'y' => $y]) | ||
); | ||
|
||
return $frame; | ||
} | ||
} |