I need to draw various font sizes onto a canvas to create a web service. Wanting to protect my HD assets, the intent is to use PHP to populate the image with the necessary text, and then scale down the image before presenting it to the user. A similar service already exists, a tool to allow the public to make user generated content for a card game.
The problem ever, is that PHP does not seem to handle font sizes very well. I created this sample code to demonstrate my issue. Here is a sample output from the code below
<?php
$img = imagecreatetruecolor(750, 530);
$black = imagecolorallocate($img, 0, 0, 0);
$gray = imagecolorallocate($img, 125, 125, 125);
$white = imagecolorallocate($img, 255, 255, 255);
$font = realpath('../fonts/micross.ttf');
$size = 12;
$spacing = 20;
for ($x = 0; $x <= 25; $x++) {
$box = imageftbbox($size + $x/10, 0, $font, "The longer the phase the more apparent the size difference should be");
$boxWidth = $box[2] - $box[0];
imagefilledrectangle($img, 5, $x*$spacing+5, $boxWidth+5, ($x+1)*$spacing+5, $gray);
imagefttext($img, $size + $x/10, 0, 5, $spacing*($x+1), $white, $font, "The longer the phase the more apparent the size difference should be Font Size ".($size+($x/10)));
}
imagejpeg($img);
imagedestroy($img);
?>
You can see how despite the font size steadily increasing by 0.1, it sporadically jumps at what seem at first like random intervals, however if you increase the number of loops and log the data, you can see that it alternates between increasing every 0.7, and 0.8. Unfortunately that doesn't help me any, just some insight.
if($last != $boxWidth)
{
$last = $boxWidth;
echo $boxWidth." ".($size+($x/10))."<br>";
}
This outputs the current width and font size each time the text width changes. I've compiled a sample output for you guys to look at here
Hopefully I've provided enough information to get some help, this has been very frustrating.