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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:39:06+00:00 2026-06-16T04:39:06+00:00

Ok, so I’m learning how to use the GD library of PHP to generate

  • 0

Ok, so I’m learning how to use the GD library of PHP to generate polls, images, etc.. The thing is that when it comes to the image output using the imagejpeg function, nothing shows on the screen. For this exercise, I am typing text on a HTML forum, which needs to be put on an image using the GD library, basically putting text on an image. It’s pretty straight-forward, I just don’t understand why my image won’t show. Below is both the HTML form code and the PHP code.

HTML form:

<html>
    <head> 
        <title> Create Buttons </title> 
    </head>
    <body>
        <form action ="button.php" method ="post">
            <p> Type button text here </p>
            <input type="text" name="button_text" size ="20" />
            <p> Choose button color: </p>
            <input type ="radio" name="color" value="red"> Red <br>
            <input type ="radio" name="color" value="green"> Green <br>
            <input type ="radio" name="color" value="blue"> Blue <br>
            <input type ="submit" value ="Create Button" />
        </form>    
    </body>
</html>

PHP code:

<?php
Header('Content-type: image/jpeg');
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
$button_text = $_POST['button_text']; var_dump($button_text);
$color = $_POST['color']; var_dump($color);
if(empty($color) || empty($button_text)) {
    echo " Could not create image - form not filled correctly";
    exit;
}
$path = $DOCUMENT_ROOT."/uploads/$color-button.jpg";
$im = imagecreatefromjpeg ($path);
$width_image = imagesx($im);
$height_image = imagesy($im);

$width_image_wo_margins = $width_image-(2*18);
$height_image_wo_margins = $width_image-(2*18);

$font_size = 33;
putenv('GDFONTPATH=C:\Windows\Fonts');

$fontname = getenv('GDFONTPATH') . '\comic.ttf';
if(!is_file($fontname)) {
    die( "Missing Font");
}

do {
    $font_size--;
    $bbox = imagettfbbox($font_size,0,$fontname,$button_text);
    $right_text = $bbox[2];
    $left_text = $bbox[0];
    $width_text  = $right_text -$left_text;
    $height_text = abs($bbox[7] - $bbox[1]);
}

while($font_size > 8 && ( $height_text > $height_image_wo_margins || $width_text > $width_image_wo_margins));

if ( $height_text > $height_image_wo_margins || $width_text > $width_image_wo_margins) {
    echo "Text given wil not fit on button.<br />";
} else {
    $text_y = $width_image/2.0 - $width_text/2.0;
    $text_x = $height_image/2.0 - $height_text/2.0;

    if($left_text < 0) {
        $text_x += abs($left_text); //add factor for left overhang.  
    }
    $above_line_text = abs($bbox[7]);
    $text_y += $above_line_text;
    $text_y -=2;
    $white = imagecolorallocate($im,255,255,255);
    imagettftext($im, $font_size, 0, $text_x, $text_y, $white, $fontname, $button_text);

    imagejpeg($im, NULL,75); 
}
imagedestroy($im);
?>
  • 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-16T04:39:07+00:00Added an answer on June 16, 2026 at 4:39 am

    Your problem is the var_dump statement.

    That is sending text to your output. The imagejpeg() call is probably creating the image fine, but it will not render with the var_dump statement.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am using jsonparser to parse data and images obtained from json response. When
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is

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.