Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb20a47

Browse files
authored
Add support for variables in text style
1 parent c5d6484 commit bb20a47

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

src/Transformation/Layer/TextSource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function text($text)
9999
/**
100100
* Sets the text style.
101101
*
102-
* @param array|TextStyle $style The text style.
102+
* @param string|array|TextStyle $style The text style.
103103
*
104104
* @return $this
105105
*/

tests/Unit/Transformation/Image/TextStyleTest.php

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,22 @@
1010

1111
namespace Cloudinary\Test\Unit\Transformation\Image;
1212

13+
use Cloudinary\Asset\Image;
14+
use Cloudinary\Test\Unit\Asset\AssetTestCase;
1315
use Cloudinary\Transformation\Argument\Text\FontAntialias;
1416
use Cloudinary\Transformation\Argument\Text\FontFamily;
1517
use Cloudinary\Transformation\Argument\Text\FontWeight;
16-
use Cloudinary\Transformation\Argument\Text\Stroke;
1718
use Cloudinary\Transformation\Argument\Text\TextAlignment;
1819
use Cloudinary\Transformation\Argument\Text\TextDecoration;
20+
use Cloudinary\Transformation\Expression\Expression;
21+
use Cloudinary\Transformation\ImageSource;
1922
use Cloudinary\Transformation\TextStyle;
20-
use PHPUnit\Framework\TestCase;
23+
use Cloudinary\Transformation\Transformation;
2124

2225
/**
2326
* Class TextStyleTest
2427
*/
25-
final class TextStyleTest extends TestCase
28+
final class TextStyleTest extends AssetTestCase
2629
{
2730
public function testTextStyle()
2831
{
@@ -42,4 +45,35 @@ public function testTextStyle()
4245
->stroke()
4346
);
4447
}
48+
49+
public function testTextLayerStyleIdentifierVariables()
50+
{
51+
$image = new Image(self::IMAGE_NAME);
52+
$image->addTransformation(
53+
(new Transformation())
54+
->addVariable('$style', '!Arial_12!')
55+
->overlay(
56+
ImageSource::text('hello-world')->textStyle('$style')
57+
)
58+
);
59+
60+
self::assertImageUrl(
61+
'$style_!Arial_12!/l_text:$style:hello-world/fl_layer_apply/' . self::IMAGE_NAME,
62+
$image->toUrl()
63+
);
64+
65+
$image = new Image(self::IMAGE_NAME);
66+
$image->addTransformation(
67+
(new Transformation())
68+
->addVariable('$style', '!Arial_12!')
69+
->overlay(
70+
ImageSource::text('hello-world')->textStyle(new Expression('$style'))
71+
)
72+
);
73+
74+
self::assertImageUrl(
75+
'$style_!Arial_12!/l_text:$style:hello-world/fl_layer_apply/' . self::IMAGE_NAME,
76+
$image->toUrl()
77+
);
78+
}
4579
}

0 commit comments

Comments
 (0)