Skip to content

Commit

Permalink
use 96 ppi resolution in imagick and gmagick drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
avalanche123 committed May 12, 2012
1 parent 12a02c7 commit 2637e79
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
7 changes: 6 additions & 1 deletion lib/Imagine/Gmagick/Drawer.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,12 @@ public function text($string, AbstractFont $font, PointInterface $position, $ang
$text = new \GmagickDraw();

$text->setfont($font->getFile());
$text->setfontsize($font->getSize());
/**
* @see http://www.php.net/manual/en/imagick.queryfontmetrics.php#101027
*
* ensure font resolution is the same as GD's hard-coded 96
*/
$text->setfontsize((int) ($font->getSize() * (96 / 72)));
$text->setfillcolor($pixel);

$info = $this->gmagick->queryfontmetrics($text, $string);
Expand Down
7 changes: 6 additions & 1 deletion lib/Imagine/Gmagick/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ public function box($string, $angle = 0)
$text = new \GmagickDraw();

$text->setfont($this->file);
$text->setfontsize($this->size);
/**
* @see http://www.php.net/manual/en/imagick.queryfontmetrics.php#101027
*
* ensure font resolution is the same as GD's hard-coded 96
*/
$text->setfontsize((int) ($this->size * (96 / 72)));
$text->setfontstyle(\Gmagick::STYLE_OBLIQUE);

$info = $this->gmagick->queryfontmetrics($text, $string);
Expand Down
12 changes: 11 additions & 1 deletion lib/Imagine/Imagick/Drawer.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,17 @@ public function text($string, AbstractFont $font, PointInterface $position, $ang
$text = new \ImagickDraw();

$text->setFont($font->getFile());
$text->setFontSize($font->getSize());
/**
* @see http://www.php.net/manual/en/imagick.queryfontmetrics.php#101027
*
* ensure font resolution is the same as GD's hard-coded 96
*/
if (version_compare(phpversion("imagick"), "3.0.2", ">=")) {
$text->setResolution(96, 96);
$text->setFontSize($font->getSize());
} else {
$text->setFontSize((int) ($font->getSize() * (96 / 72)));
}
$text->setFillColor($pixel);
$text->setTextAntialias(true);

Expand Down
15 changes: 13 additions & 2 deletions lib/Imagine/Imagick/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,21 @@ public function __construct(\Imagick $imagick, $file, $size, Color $color)
*/
public function box($string, $angle = 0)
{
$text = new \ImagickDraw();
$text = new \ImagickDraw();

$text->setFont($this->file);
$text->setFontSize($this->size);

/**
* @see http://www.php.net/manual/en/imagick.queryfontmetrics.php#101027
*
* ensure font resolution is the same as GD's hard-coded 96
*/
if (version_compare(phpversion("imagick"), "3.0.2", ">=")) {
$text->setResolution(96, 96);
$text->setFontSize($this->size);
} else {
$text->setFontSize((int) ($this->size * (96 / 72)));
}

$info = $this->imagick->queryFontMetrics($text, $string);

Expand Down
2 changes: 1 addition & 1 deletion tests/Imagine/Gmagick/ImagineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function setUp()

protected function getEstimatedFontBox()
{
return new Box(86, 41);
return new Box(117, 55);
}

protected function getImagine()
Expand Down
2 changes: 1 addition & 1 deletion tests/Imagine/Imagick/ImagineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function setUp()

protected function getEstimatedFontBox()
{
return new Box(85, 41);
return new Box(116, 55);
}

protected function getImagine()
Expand Down

0 comments on commit 2637e79

Please sign in to comment.