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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:34:59+00:00 2026-05-18T20:34:59+00:00

I have a variable ( $output ) that is set to a string. To

  • 0

I have a variable ($output) that is set to a string.

To mekt this string an image I’m using the PHP: GD Library.

In particular the imagestring() function, which I’m using with a very slight modification:

<?php
// Create a 100*30 image
$im = imagecreate(100, 30);

// White background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);

// Write the string at the top left
imagestring($im, 5, 0, 0, $output, $textcolor); #here is my string $output

// Output the image
header('Content-type: image/png');

imagepng($im);
imagedestroy($im);
?>

This is working as expected: It turns $output into an image.

So, my problem is (or my best guess at least):

header('Content-type: image/png');

Which, doesn’t allow me to output any html after that.

So I read this question, which asks if you can use two headers, which you can’t, but the accepted answer recommends, something like this: <img src="my_img.php" />

This of course would be fine, except I don’t know how would this solve my issues since, since even if I knew the source to this image (which I don’t – so, that would be my first question, what’s the path to the generated image*) I’t would change the fact that the header is there and is not letting me output text.

So, I how would you approach this issue?

Thanks in advance!!


*I guess that would solve my issues since I could do this on an external file, and the just call the image (but maybe not since I would have to do an include and this would include the header too) as you see I’m a bit confused. Sorry 🙂


UPDATE:

So I’m seeing my question was confusing so I will add some more code to see if this clarifies my problem a little bit more:

<?php

$x = mt_rand(1,5);
$y = mt_rand(1,5);

function add($x, $y) { return $x + $y; }
function subtract($x, $y) { return $x - $y; }
function multiply($x, $y) { return $x * $y; }

$operators = array(
    'add',
    'subtract', 
    'multiply'
    );

$rdno = $operators[array_rand($operators)];

$result = call_user_func_array($rdno, array($x, $y));
session_start();
$_SESSION['res'] = $result;

if ($rdno == "add") {
    $whato = "+";
}elseif ($rdno == "subtract") {
    $whato = "-";
} else {
    $whato = "*";
}
$output = $x . $whato . $y . " = ";
?>
<form name="input" action="check.php" method="post">
<input type="text" name="result" />
<input type="submit" value="Check" />
</form>

I want $output to be a image so this got me trying to use the PHP:GD script above, but I can’t make put in the same file because of the header.

  • 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-05-18T20:35:00+00:00Added an answer on May 18, 2026 at 8:35 pm

    You need to make a separate PHP script which serves the image, then make an <img> tag that points to this script.

    You can send information to the script using the querystring in the image URL.

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

Sidebar

Related Questions

I have a variable that contains a 4 byte, network-order IPv4 address (this was
I have a variable of type Hashmap <String,Integer >. In this, the Integer value
I have a variable last_login and want to output a message if the last
If I have variable of type IEnumerable<List<string>> is there a LINQ statement or lambda
I have a variable that is built in loop. Something like: $str = ;
If I have a variable in C# that needs to be checked to determine
I have a UITableView cell that is going to have a variable size depending
I have a variable of type Dynamic and I know for sure one of
I have a variable of type Number, and i like to obtain the sign
Suppose I have a variable of type Int = 08, how can I convert

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.