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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:54:35+00:00 2026-05-26T10:54:35+00:00

I am using this code to create an image <?php // Set the content-type

  • 0

I am using this code to create an image

<?php

 // Set the content-type
 header('Content-Type: image/png');

 // Create the image
 $im = imagecreatetruecolor(400, 30);

 // Create some colors
 $white = imagecolorallocate($im, 255, 255, 255);
 $grey = imagecolorallocate($im, 128, 128, 128);
 $black = imagecolorallocate($im, 0, 0, 0);
 imagefilledrectangle($im, 0, 0, 399, 29, $white);

 // The text to draw
 $text = 'Testing...';
 // Replace path by your own font path
 $font = 'arial.ttf';

 // Add some shadow to the text
 imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

  // Add the text
  imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

  // Using imagepng() results in clearer text compared with imagejpeg()
  (A)print ('<div class="test">');
  imagepng($im);
  print ('</div>');
  (B)imagedestroy($im);
  ?>

The code work fines if i comment the line number ‘A’ and ‘B’ and it generates the image on the browser with testing written on it. But i want the image to be in a div. so i uncomment the line (A) and (B) but it is not giving right output. The generated html is also strange generated html is

<img src="http://localhost/php/test92.php" alt="The image “http://localhost/php/test92.php” cannot be displayed, because it contains errors.">
  • 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-26T10:54:36+00:00Added an answer on May 26, 2026 at 10:54 am

    Basically, to create dynamic image in HTML, you will need 2 PHP files:

    1. one for the image itself
    2. another one for PHP to display it.

    Let’s take a look how to do it:

    1. You create image.php that accept parameter, like: image ID or file name. For security reason, you HAVE to filter whatever parameter it get.

      Why you have to do this? because, to generate image, you can’t mix it with another HTML output. Let alone a single space or return as this will render the image broken.

    2. You do the HTML thing on another PHP, say test92.php. To the HTML logic here, like:

      1. get image data
      2. loop the data
      3. display image => <img src="image.php?imageID=12" alt="" />
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this piece of php code to create and rotate an image. And
I'm using a php script to create image thumbnails and this error is thrown
Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
I'm using PHP5 to create XML files. I have code like this: $doc =
i am trying to create slider movement graphics. The code explain better this. using
I am using this code to make the user input a name to create
Trying to replace this jquery code with some php server side magic: $(document).ready(function() {
I use this code to send an image from desktop application to a php
I created a class under 'src' dir. I'm using this code to access the
Using this code to zip a folder and it works perfect on small files

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.