Jump to content

BlackDragonIV

New Members
  • Posts

    5
  • Joined

  • Last visited

Everything posted by BlackDragonIV

  1. I decided to make a sample program using ImageMagick to test it's font-size loss and got significantly better results. I've updated the spreadsheet from earlier to include my ImageMagick results, GD has a font-size pool of only 13.33%, where ImageMagick has a font-size pool of 54.5%. That's a 4x increase! <?php function setFont($fillColor, $backgroundColor) { $draw = new \ImagickDraw(); $imagick = new \Imagick(); $draw->setStrokeColor('none'); $draw->setFillColor($fillColor); $draw->setTextAntialias(true); $draw->setFont("../fonts/pala.ttf"); //$draw->setFont("../fonts/micross.ttf"); $text = "The longer the phrase the more apparent the size should be"; $startSize = 12; $loops = 200; $draw->setFontSize($startSize + ($loops*0.1)); $fontMetrics = $imagick->queryFontMetrics($draw, $text." Width: 9999"); //var_dump($fontMetrics); //echo "Length of array: ".sizeof($fontMetrics)."<br>"; $width = $fontMetrics["textWidth"];//->textWidth(); $spacing = $fontMetrics["textHeight"];//->textWidth(); $last = 0; for($x = 0; $x < $loops; $x++) { $draw->setFontSize($startSize + ($x*0.1)); $fontMetrics = $imagick->queryFontMetrics($draw, $text); $width = $fontMetrics["textWidth"]; if($last != $width) { $last = $width; //echo $width." ".($startSize+($x*0.1))."<br>"; } $draw->annotation(0, $spacing*($x+1), $text." Width: ".$fontMetrics["textWidth"]); } $fontMetrics = $imagick->queryFontMetrics($draw, $text." Width: ".$fontMetrics["textWidth"]); $width = $fontMetrics["textWidth"]; $imagick->newImage($width, $spacing*$loops, $backgroundColor); $imagick->setImageFormat("png"); $imagick->drawImage($draw); header("Content-Type: image/png"); echo $imagick->getImageBlob(); } setFont("black","white"); ?> Here's that new sample code. Unfortunately since I am only a community member of this card game I am unable to acquire SVG graphics -- Needless to say, if I can just draw SVG text onto my bitmaps, then I don't see why that wouldn't work. I think re-scaling would introduce artifacts into the background images (But I haven't tested it). I considered re-scaling the font by itself before layering it onto the card, but I don't think GD supports a transparent canvas.
  2. Well, now that I'm armed with the information at hand, I've got a few options: Settle with what I've got and work in increments of 0.75pt size Try the imagemagick functions Upscale & Downscale Use an entirely different language to build the card image with a better font renderer and then pull the image into the site via PHP Any thoughts or opinions?
  3. I want better sub pixel rendering so that I can render text to an accuracy of 0.1pt size.
  4. Apologies for how poorly written the post is. I would fix it, but I am unable to edit the post. -- Sorry about that.
  5. 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.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.