Skip to content

Commit

Permalink
Merge pull request #624 from lupka/kerning
Browse files Browse the repository at this point in the history
Add support for text kerning (ImageMagick only)
  • Loading branch information
olivervogel committed Jul 6, 2021
2 parents a53dcf6 + 8608eb0 commit a6efcd4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Intervention/Image/AbstractFont.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ abstract class AbstractFont
*/
public $valign;

/**
* Space between text characters
*
* @var float
*/
public $kerning = 0;

/**
* Path to TTF or GD library internal font file of the text
*
Expand Down Expand Up @@ -218,6 +225,27 @@ public function getValign()
return $this->valign;
}

/**
* Set text kerning
*
* @param string $kerning
* @return void
*/
public function kerning($kerning)
{
$this->kerning = $kerning;
}

/**
* Get kerning
*
* @return float
*/
public function getKerning()
{
return $this->kerning;
}

/**
* Set path to font file
*
Expand Down
14 changes: 14 additions & 0 deletions src/Intervention/Image/Gd/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,18 @@ public function applyToImage(Image $image, $posx = 0, $posy = 0)
imagestring($image->getCore(), $this->getInternalFont(), $posx, $posy, $this->text, $color->getInt());
}
}

/**
* Set text kerning
*
* @param string $kerning
* @return void
*/
public function kerning($kerning)
{
throw new \Intervention\Image\Exception\NotSupportedException(
"Kerning is not supported by GD driver."
);
}

}
1 change: 1 addition & 0 deletions src/Intervention/Image/Imagick/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function applyToImage(Image $image, $posx = 0, $posy = 0)

$draw->setFontSize($this->size);
$draw->setFillColor($color->getPixel());
$draw->setTextKerning($this->kerning);

// align horizontal
switch (strtolower($this->align)) {
Expand Down
7 changes: 7 additions & 0 deletions tests/AbstractFontTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public function testValign()
$this->assertEquals('top', $font->valign);
}

public function testKerning()
{
$font = $this->getMockForAbstractClass('\Intervention\Image\AbstractFont');
$font->kerning(10.5);
$this->assertEquals(10.5, $font->kerning);
}

public function testFile()
{
$font = $this->getMockForAbstractClass('\Intervention\Image\AbstractFont');
Expand Down

0 comments on commit a6efcd4

Please sign in to comment.