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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:03:57+00:00 2026-05-26T15:03:57+00:00

I have the following code which works perfectly fine in my php file and

  • 0

I have the following code which works perfectly fine in my php file and generates a histogram image. However as soon as I add an html tags it wouldn’t generate a histogram anymore but an empty image. It seems to me that the problem is in the first line header("Content-type: image/jpeg");. But how can i fix it?

<html>
    <?php
        // Send the PNG header information. Replace for JPEG or GIF or whatever
        header("Content-type: image/jpeg");

            // This array of values is just here for the example.
            $data = array('3400','2570','245','473','1000','3456','780');

            // Get the total value of columns we are going to plot
            $sum = array_sum($data);

            // Get the height and width of the final image
            $height = 255;
            $width = 320;

            $im = imagecreate($width,$height); // width , height px

            // Generate the image variables
            $white = imagecolorallocate($im,255,255,255); 
            $black = imagecolorallocate($im,0,0,0);   
            $red = imagecolorallocate($im,255,0,0);   


            imageline($im, 10, 5, 10, 230, $black);
            imageline($im, 10, 230, 300, 230, $black);

            // Now plot each column
            $x = 15;   
            $y = 230;   
            $x_width = 20;  
            $y_ht = 0; 

            for ($i=0;$i<7;$i++){

              $y_ht = ($data[$i]/$sum)* $height;    

                  // This part is just for 3D effect
              imagerectangle($im,$x,$y,$x+$x_width,($y-$y_ht),$red);
                  imagestring( $im,2,$x-1,$y+10,$data[$i],$black);

              $x += ($x_width+20);  

            }

            imagejpeg($im);

    ?> 
</html>
  • 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-26T15:03:58+00:00Added an answer on May 26, 2026 at 3:03 pm

    Remove the tag in your PHP file as it’s not HTML document.
    Make sure there’s no space before
    <?php
    open tag.

    Call that file within and img tag like

    <img src="genrated.jpg.php" />

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

Sidebar

Related Questions

I have the following code which works fine. However, I only want to return
I have the following code, which works perfectly fine in every browser except for
I have the following code which works perfectly, but I want to allow access
I have the following code which works just fine when the method is POST,
At the moment I have the following code which works fine. label = new
I have the following PHP code which works out the possible combinations from a
I have the following code for Android which works fine to play a sound
I have code that looks like the following, which works fine for displaying the
I have the following code which works perfectly but I need an onblur statement
I have the following code which works when i put it in any blank

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.