Skip to content

Commit

Permalink
add x/y boundaries to text method
Browse files Browse the repository at this point in the history
  • Loading branch information
antonlukin committed Mar 31, 2024
1 parent d8e6bfe commit 179f840
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ $image->text(
'This text appears right after title using smart boundaries',
array(
'x' => 50,
'y' => 100 + $boundary['height'],
'y' => $boundary['y'] + $boundary['height'],
'width' => 800,
'fontpath' => '/fonts/opensans.ttf',
'fontsize' => 20,
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "antonlukin/poster-editor",
"version": "5.11",
"version": "5.12",
"description": "Wrapper for PHP's GD Library for easy image manipulation",
"keywords": ["php", "image", "text", "gd"],
"homepage": "https://github.com/antonlukin/poster-editor",
Expand Down
2 changes: 1 addition & 1 deletion example/boundary.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
'This text appears right after title using smart boundaries',
array(
'x' => 50,
'y' => 100 + $boundary['height'],
'y' => $boundary['y'] + $boundary['height'],
'width' => 800,
'fontpath' => 'fonts/opensans.ttf',
'fontsize' => 20,
Expand Down
17 changes: 11 additions & 6 deletions src/PosterEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @package PosterEditor
* @author Anton Lukin <[email protected]>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @version Release: 5.11
* @version Release: 5.12
* @link https://github.com/antonlukin/poster-editor
*/
class PosterEditor
Expand Down Expand Up @@ -774,7 +774,14 @@ public function text($text, $options = array(), &$boundary = array())
$lines = explode(PHP_EOL, $text);

// Set default boundary vaules.
$boundary = array_merge(array('width' => 0, 'height' => 0));
$boundary = array_merge(
array(
'x' => $options['x'],
'y' => $options['y'],
'width' => 0,
'height' => 0,
)
);

foreach ($lines as $index => $line) {
list($x, $y, $width, $height) = $this->getOffset($options, $lines, $index);
Expand All @@ -785,10 +792,8 @@ public function text($text, $options = array(), &$boundary = array())
// Draw single line
$this->drawLine($line, $options, $width, $x, $y, $color, $last);

$boundary = array(
'width' => max($width, $boundary['width']),
'height' => $boundary['height'] + $height,
);
$boundary['width'] = max($width, $boundary['width']);
$boundary['height'] = $boundary['height'] + $height;
}

return $this;
Expand Down

0 comments on commit 179f840

Please sign in to comment.