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

  • Home
  • SEARCH
  • 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 8228351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:25:51+00:00 2026-06-07T16:25:51+00:00

I have an problem with PHP function imagettftext. I have code for generating card

  • 0

I have an problem with PHP function imagettftext. I have code for generating card images from database with text informations. And with some cards I have problem – words are written over each other (like here).

My code looks like this (font size changes depending on the length of the text)

            $length = strlen($cardInfo->description);
            if ($length < 15) {
                $divide = 15;
                $fontSize = 16;
                $lineHeight = 25;
                $startPos = 220;
            } else if ($length < 70) {
                $divide = 25;
                $fontSize = 12;
                $lineHeight = 18;
                $startPos = 210;
            } else if ($length < 110) {
                $divide = 28;
                $fontSize = 10;
                $lineHeight = 14;
                $startPos = 210;
            } else {
                $divide = 38;
                $fontSize = 8;
                $lineHeight = 13;
                $startPos = 210;
            }
            $description = wordwrap($cardInfo->description, $divide, ">>>");
            $lines = explode(">>>", $description);
            $count = 0;
            foreach ($lines as $line) {
                $position = $count * $lineHeight;
                $count++;
                imagettftext($image, $fontSize, 0, 28, ($startPos + $position), $black, $font, $line);
            }

and the text in the database looks like this:

Oblehací stroj

Imunita vůči střelám /Tato jednotka je imunní vůči střeleckým zraněním/

Other problem is with the line wrapping: here. I don’t know why the word “jídlo” is on the next line.

Thank you for any answers!

  • 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-07T16:25:52+00:00Added an answer on June 7, 2026 at 4:25 pm

    Long time ago, I have written a quite complex class to archive a similar task.

    I don’t have this code anymore, but the steps are fairly simple.

    First: Don’t rely on the calculations, php does on rare fonts.

    Php’s wordwrap-function is senseless here, because you deal with a charset-width (e.g. tracking) unknown to php. Wordwrap assumes, that all characters have the same char-width.

    So, you have to build your own wordwrap-function using imagettfbbox. Then, you’ll have to determine the size of the lowercase “x”-letter and the uppercase “X”-letter. These letters are the norm to calculate your own line-height/line-spacing. I also recommend you to manually separate words, since PHP does not always recognize the white-space-width correctly.

    Hope this could help you…

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

Sidebar

Related Questions

I have a bizzare problem with php date function. code: $numDays = 8; $date
i have a problem using some php functions on a string i get from
I have a problem in php code inserting values into database (I use PHPMyAdmin).
I have a problem sending images through the PHP mail function. I have used
Hi i have problem with some things Here is the code function get_char_val(merk) {
i have this strange problem with the PHP function CTYPE_ALNUM if i do: PHP:
In PHP I have a function, the problem is it will output an extra
I have a little problem with some preg_replace functions in PHP. First I have
I have a problem making a select tag in php code dynamic. I'm creating
I have a problem using php rename function. If I use the following syntax

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.