Skip to content

Commit d9cef76

Browse files
committed
added justify alignment to text method
1 parent 826f86c commit d9cef76

9 files changed

Lines changed: 225 additions & 3439 deletions

File tree

README.md

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,21 @@ Rotate image. Set an angle in degrees and optional color of the uncovered zone a
210210
```
211211
$image->text(string $text, array $options = array(), array &$boundary = array())
212212
```
213-
Draw text on image. Look for all possible options in the examples below.
213+
Draw text on image. Possible options:
214+
- **x**: X-Coordinate of text box starting point.
215+
- **y**: Y-Coordinate of text box starting point.
216+
- **width**: Width of text box. Calculated from image size for nulled values.
217+
- **height**: Height of text box. Calculated from image size for nulled values.
218+
- **fontsize**: Maximum font size. Will be scaled down if the text doesn't fit box.
219+
- **color**: Color of text. Can be rgb-array or '#ffffff' format.
220+
- **lineheight**: Line height of text.
221+
- **opacity**: Text opacity from 0 to 100.
222+
- **horizontal**: Horizontal alignment. Can be left/right/center/justify.
223+
- **vertical**: Vertical alginment. Can be top/center/bottom/justify.
224+
- **fontpath**: Path to .ttf font file.
225+
- **debug**: Draws text box rectangle if true.
226+
227+
Use boundary to get actual dimensions of the drawn text box. See detailed examples below.
214228

215229
## Examples
216230

@@ -238,11 +252,11 @@ $image->text(
238252
array(
239253
'x' => 100,
240254
'y' => 100,
241-
'width' => 1000, // Use image width if null or unset
242-
'height' => 400, // Use image height if null or unset
243-
'horizontal' => 'center', // Can be left/right/center
244-
'vertical' => 'center', // Can be top/center/bottom
245-
'fontpath' => 'fonts/opensans.ttf', // Can only be .ttf
255+
'width' => 1000,
256+
'height' => 400,
257+
'horizontal' => 'center',
258+
'vertical' => 'center',
259+
'fontpath' => 'fonts/opensans.ttf',
246260
'fontsize' => 24,
247261
'lineheight' => 1.75,
248262
'color' => '#ffffff',
@@ -256,6 +270,35 @@ $image->show('jpg', 70);
256270
#### Result
257271
<img src="example/samples/center.jpg" alt="multiline centered text" width="400" />
258272

273+
### Draw and justify multiline text
274+
```php
275+
$image = new PosterEditor\PosterEditor();
276+
$image->make('images/bridge.jpg')->fit(900, 600);
277+
$image->blackout(70);
278+
279+
$image->text(
280+
'Lorem ipsum dolor d d 4 g sit amet, consectetur adipiscing et, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex eas commodo consequat sdfsdfl', // phpcs:ignore
281+
array(
282+
'x' => 100,
283+
'y' => 100,
284+
'width' => 600,
285+
'height' => 400,
286+
'horizontal' => 'justify',
287+
'vertical' => 'justify',
288+
'fontpath' => 'fonts/opensans.ttf',
289+
'fontsize' => 20,
290+
'lineheight' => 1.5,
291+
'color' => '#ffffff',
292+
'opacity' => 1,
293+
'debug' => true,
294+
)
295+
);
296+
297+
$image->show('png');
298+
```
299+
#### Result
300+
<img src="example/samples/justify.png" alt="multiline justified text" width="400" />
301+
259302
### Use boundaries to draw one title right after another
260303
```php
261304
$image = new PosterEditor\PosterEditor();

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "antonlukin/poster-editor",
3-
"version": "5.7",
3+
"version": "5.8",
44
"description": "Wrapper for PHP's GD Library for easy image manipulation",
55
"keywords": ["php", "image", "text", "gd"],
66
"homepage": "https://github.com/antonlukin/poster-editor",
@@ -26,5 +26,10 @@
2626
"files": [
2727
"src/PosterEditor.php"
2828
]
29+
},
30+
"config": {
31+
"allow-plugins": {
32+
"dealerdirect/phpcodesniffer-composer-installer": true
33+
}
2934
}
3035
}

0 commit comments

Comments
 (0)