-2

This is drawing.php file having class GeoDrawing and method image which creates the image. I now create the object of this class and call the function and image return successfully.

When I include this file 'drawing.php' to another php file - let say server.php - then this function does not return image.

Please help me out. What is going wrong with this code?

class GeoDrawing
{        
    public  $canvas;

     function Image()
     {        
        $this->canvas = imagecreate(2600, 1200) or die("Cannot Initialize new GD image stream");
        imagecolorallocate($this->canvas, 225, 225, 225);
        header('Content-Type: image/jpeg');  
        imagejpeg($home->canvas);       
     }
}

$home = new GeoDrawing();
$home->image();
7
  • In addition to what @wavemode said... I would gladly edit your post to make it more comprehensible but it is so bad I'm lost at what you are trying to say. Please revise this. Commented Sep 11, 2014 at 5:04
  • ok am new here if you got my point then help me plz.. Commented Sep 11, 2014 at 5:18
  • It could be a lot of things. Does your server.php prints any additional output? Commented Sep 11, 2014 at 5:23
  • You've got display_errors on, right? .. right? Commented Sep 11, 2014 at 5:23
  • not error just small dummy pic show on top left corner of the browser Commented Sep 11, 2014 at 5:25

1 Answer 1

0

The problem is, your function does not "return" anything. It prints out the image. As such it does not work if anything was printed out before the function call. That us because you are setting a header. And imagejpeg prints out the image, so if you have any output after that, it gets added to your image data and corrupts it. I would suggest reviewing your server.php to ensure no printout bevore function call. And perhaps use an exit() inside your function to ensure no orintout afterwards. But remember, that this stops execution so the function would never return.

Edit:

Your program is throwing errors! Please comment the header() to view them. Because else your browser expects a valid image and instead gets php error messages.

your codeproblem is a scope typo:

imagejpeg($home->canvas);  

to

imagejpeg($this->canvas);  

To help you understand your problem, you can look at others having similar problems, i think that gives a good example.

Sign up to request clarification or add additional context in comments.

7 Comments

<?php include "Drawing.php"; $home = new GeoDrawing(); $home->image(); ?>
Is there any space character before the <?php ?
Can you view the source code of your site? Because of your new mime type errors are not displayed as text
i have no site just using local Linux server plz give me your gmail id the i will send you the source code
Please use Strg + U and tell me the text your browser displays
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.