Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow angle config in degrees #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/Box.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace GDText;

use GDText\Struct\Point;
Expand All @@ -11,6 +12,11 @@ class Box
*/
protected $im;

/**
* @var int
*/
protected $angle=0;

/**
* @var int
*/
Expand Down Expand Up @@ -120,7 +126,7 @@ public function setStrokeColor(Color $color)
{
$this->strokeColor = $color;
}

/**
* @param int $v Stroke size in *pixels*
*/
Expand All @@ -129,6 +135,14 @@ public function setStrokeSize($v)
$this->strokeSize = $v;
}

/**
* @param int $v Angle ,The angle in degrees, with 0 degrees being left-to-right reading text.
*/
public function setAngle($v)
{
$this->angle = $v;
}

/**
* @param Color $color Shadow color
* @param int $xShift Relative shadow position in pixels. Positive values move shadow to right, negative to left.
Expand Down Expand Up @@ -348,12 +362,12 @@ protected function wrapTextWithOverflow($text)
$words = explode(" ", $line);
$line = $words[0];
for ($i = 1; $i < count($words); $i++) {
$box = $this->calculateBox($line." ".$words[$i]);
$box = $this->calculateBox($line . " " . $words[$i]);
if ($box->getWidth() >= $this->box->getWidth()) {
$lines[] = $line;
$line = $words[$i];
} else {
$line .= " ".$words[$i];
$line .= " " . $words[$i];
}
}
$lines[] = $line;
Expand Down Expand Up @@ -390,7 +404,7 @@ protected function calculateBox($text)
{
$bounds = imagettfbbox($this->getFontSizeInPoints(), 0, $this->fontFace, $text);

$xLeft = $bounds[0]; // (lower|upper) left corner, X position
$xLeft = $bounds[0]; // (lower|upper) left corner, X position
$xRight = $bounds[2]; // (lower|upper) right corner, X position
$yLower = $bounds[1]; // lower (left|right) corner, Y position
$yUpper = $bounds[5]; // upper (left|right) corner, Y position
Expand Down Expand Up @@ -419,7 +433,7 @@ protected function drawInternal(Point $position, Color $color, $text)
imagettftext(
$this->im,
$this->getFontSizeInPoints(),
0, // no rotation
$this->angle,
$position->getX(),
$position->getY(),
$color->getIndex($this->im),
Expand Down