summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy DECOOL <contact@jdecool.fr>2015-06-10 22:24:23 +0200
committerJérémy DECOOL <contact@jdecool.fr>2015-06-10 22:24:23 +0200
commitad776c73632c5d14366c6eb979f2769c1c0c45a5 (patch)
treef80bc2c7bb5dee6f8062f747742de26fb7361699
parent5d4d5e80c6c42bf26d232536ffb4205f4326d08e (diff)
downloadImageWorkshop-origin/feature/font-spacing.zip
ImageWorkshop-origin/feature/font-spacing.tar.gz
ImageWorkshop-origin/feature/font-spacing.tar.bz2
Add spacing letter configuration for ImageWorkshopLayer::write functionorigin/feature/font-spacing
-rw-r--r--src/PHPImageWorkshop/Core/ImageWorkshopLayer.php17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php
index 185a0e3..2ca1d2b 100644
--- a/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php
+++ b/src/PHPImageWorkshop/Core/ImageWorkshopLayer.php
@@ -1399,10 +1399,11 @@ class ImageWorkshopLayer
* @param integer $positionX
* @param integer $positionY
* @param integer $fontRotation
+ * @param integer $spacing
*
* @return array
*/
- public function write($text, $fontPath, $fontSize = 13, $color = 'ffffff', $positionX = 0, $positionY = 0, $fontRotation = 0)
+ public function write($text, $fontPath, $fontSize = 13, $color = 'ffffff', $positionX = 0, $positionY = 0, $fontRotation = 0, $spacing = 0)
{
if (!file_exists($fontPath)) {
throw new ImageWorkshopLayerException('Can\'t find a font file at this path : "'.$fontPath.'".', static::ERROR_FONT_NOT_FOUND);
@@ -1411,7 +1412,19 @@ class ImageWorkshopLayer
$RGBTextColor = ImageWorkshopLib::convertHexToRGB($color);
$textColor = imagecolorallocate($this->image, $RGBTextColor['R'], $RGBTextColor['G'], $RGBTextColor['B']);
- return imagettftext($this->image, $fontSize, $fontRotation, $positionX, $positionY, $textColor, $fontPath, $text);
+ if (0 === $spacing) {
+ return imagettftext($this->image, $fontSize, $fontRotation, $positionX, $positionY, $textColor, $fontPath, $text);
+ }
+
+ $bbox = null;
+ $x = $positionX;
+
+ for ($i = 0; $i < strlen($text); $i++) {
+ $bbox = imagettftext($this->image, $fontSize, $fontRotation, $x, $positionY, $textColor, $fontPath, $text[$i]);
+ $x += $spacing + ($bbox[2] - $bbox[0]);
+ }
+
+ return $bbox;
}
// Manage the result