Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8162421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:42:15+00:00 2026-06-06T18:42:15+00:00

Imagick::queryFontMetrics does not seem to be working. When I use the metrics provided by

  • 0

Imagick::queryFontMetrics does not seem to be working. When I use the metrics provided by queryFontMetrics to size the image, some fonts are still being cut off. Any ideas?

Here’s my code:

if (!file_exists($cache['dirname'].'/'.$cache['basename'])) {

try {
    $draw = new ImagickDraw();
    $draw->setFont($font_path['dirname'].'/'.$font_path['basename']);
    $draw->setFontSize($size);
    $draw->setGravity(Imagick::GRAVITY_CENTER);
    $draw->setFillColor($color);

    $canvas = new Imagick();

    $metrics = $canvas->queryFontMetrics($draw, $text);

    $canvas->newImage($metrics['textWidth'], $metrics['textHeight'], "transparent", "png");
    $canvas->annotateImage($draw, 0, 0, 0, $text);

    $canvas->setImageFormat('PNG');
    mkdir($cache['dirname'], 0777, true);
    $canvas->writeImage($cache['dirname'].'/'.$cache['basename']);

    header("Content-Type: image/png");
    echo $canvas;

    $canvas->clear();
    $canvas->destroy();

    $draw->clear();
    $draw->destroy();

} catch(Exception $e) {
    // Output an error message
    echo 'Error: ',  $e->getMessage(), "";
}

} else {
    // Output the image
    $canvas = new Imagick($cache['dirname'].'/'.$cache['basename']);
    header("Content-Type: image/png");
    echo $canvas;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:42:17+00:00Added an answer on June 6, 2026 at 6:42 pm

    Okay, it looks like I’ll be answering this one myself. After quite a bit of research, I’ve discovered that it’s basically impossible to get correct metrics from the font itself. This is because each font designer could potentially define the metrics differently. The best way to proceed is to simply make the image much larger than necessary (to ensure that no clipping occurs) and then use the trim command: http://www.php.net/manual/en/imagick.trimimage.php.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

currently i'm trying to use imagick to generate some images without saving them on
I'm looking to center crop and image using Imagick PHP apis (not command line
I'm using Imagick lib to do some modifications to original image. Then I'd like
I'm having some real difficulties setting the gravity of an image in Imagick. I've
I use imagick to create thumbnails of PDF files, but in some cases imagic
I'm using php Imagick library for some image manipulation. I can distort the perspective
I've been having some trouble generating an image with the Imagick PHP extension. Everything
While i was doing some image processing, i found out that GD and Imagick
I'm trying to install imagick PHP extension on windows. It was working on PHP
I'm trying to distort an image in perspective via imagick php extension and I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.