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 8669139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:23:53+00:00 2026-06-12T18:23:53+00:00

I am making a meme generator, Imagick generating the images. My problem is that

  • 0

I am making a meme generator, Imagick generating the images. My problem is that even if I do some operations on the string I use for the image, the output is incorrect.

By example:

$_POST['text_top'] = " test test<br>"; //(starts with a space)

Then I do:

$text_top = strip_tags(trim($_POST['text_top']));

But on the display of $text_top, after I paste the variable on the image, I get:

&nbsptest test&lt;br&gt;

Why does it happen if I’m calling strip_tags and trim, from what I see, correct and as usual?

All is UTF8 encoded.

Thank!

EDIT: (full code)

function wordWrapAnnotation(&$image, &$draw, $text, $maxWidth)
{
$words = explode(" ", $text);
$lines = array();
$i = 0;
$lineHeight = 0;
while($i < count($words) )
{
    $currentLine = $words[$i];
    if($i+1 >= count($words))
    {
        $lines[] = $currentLine;
        break;
    }
    //Check to see if we can add another word to this line
    $metrics = $image->queryFontMetrics($draw, $currentLine . ' ' . $words[$i+1]);
    while($metrics['textWidth'] <= $maxWidth)
    {
        //If so, do it and keep doing it!
        $currentLine .= ' ' . $words[++$i];
        if($i+1 >= count($words))
            break;
        $metrics = $image->queryFontMetrics($draw, $currentLine . ' ' . $words[$i+1]);
    }
    //We can't add the next word to this line, so loop to the next line
    $lines[] = $currentLine;
    $i++;
    //Finally, update line height
    if($metrics['textHeight'] > $lineHeight)
        $lineHeight = $metrics['textHeight'];
}
return array($lines, $lineHeight);
}

$text_top = strip_tags(trim($_REQUEST['text_top']));
$text_bottom = strip_tags(trim($_REQUEST['text_bottom']));
$id_base = trim($_REQUEST['id_base']);

/* Création d'un nouvel objet imagick */
$im = new Imagick($_REQUEST['image']);

/* Création d'un nouvel objet imagickdraw */
$draw = new ImagickDraw();

/* Définition de la taille du texte à 52 */
$draw->setFontSize(52);
$draw->setTextAlignment(2);
$draw->setFont("impact.ttf");
$draw->setFillColor('white');
$draw->setStrokeColor("black");
$draw->setStrokeWidth(1);

/* Ajout d'un texte */
//$draw->annotation($im->getImageWidth()/2, 50, $text);
list($lines, $lineHeight) = wordWrapAnnotation($im, $draw, stripslashes($text_top), $im->getImageWidth());
$posY= 50;
for($i = 0; $i < count($lines); $i++){
$draw->annotation($im->getImageWidth()/2, $posY + $i*$lineHeight, $lines[$i]);
}

$im->drawImage($draw);
  • 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-12T18:23:55+00:00Added an answer on June 12, 2026 at 6:23 pm

    you could try this?

    $text_top = strip_tags(trim(html_entity_decode($_POST['text_top'], ENT_QUOTES, 'UTF-8'), "\xc2\xa0"));
    

    It seems like your string is html encoded.

    EDIT

    Added support for UTF-8 encoding. That way, the non-breaking space gets trimmed properly, instead of giving a ?.

    From PHP’s html_entity_decode documentation:

    Note:

    You might wonder why trim(html_entity_decode(‘ ‘)); doesn’t
    reduce the string to an empty string, that’s because the ‘ ‘
    entity is not ASCII code 32 (which is stripped by trim()) but ASCII
    code 160 (0xa0) in the default ISO 8859-1 encoding.

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

Sidebar

Related Questions

Making an adobe flex ui in which data that is calculated must use proprietary
Making websites that appear correctly in IE is a big problem. Is there any
Making a form that will accept a bunch of textual data and an image
Making a flash page that can cycle through these three images on mouseclick. For
Making an image draggable does some pretty wacky things when the image is larger
Making some Bookmarklet, I tried to use JavaScript minifier like Google Closure Compiler or
Making my first steps in RIA Services (VS2010Beta2) and i encountered this problem: created
Making UML sequence diagram in VS 2010RC I've observed that there is no activation
Making an Flex App. Just wondering if anyone has created something that fits automatically
Im making a simple rock paper scissors game and I need to use the

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.