Jump to content

Creating Images Using Php...


m3sz
 Share

Recommended Posts

Hello!I am trying to create a new image using php GD library and display it on the browser. The problem is that I havent been able to display the image yet. I also uncommented the extension php_gd2 from the php.ini file to be able to use this library and restarted apache and my pc after I did that.I am using as script an example from the php manual site at http://us.php.net/manual/en/function.imagejpeg.php, Example #1 and I am not getting the output that I should get (The output is showed in the page). What I am getting instead is an image containing the location of the php file as string (http://localhost/file.php).Can anyone help me spot the problem plz? I am out of ideas ... thanks!. I am starting to think that it is a problem with php or apache, but I am not sure... help?!?!Source code of php file<?php// Create a blank image and add some text$im = imagecreatetruecolor(120, 20);$text_color = imagecolorallocate($im, 233, 14, 91);imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);// Set the content type header - in this case image/jpegheader('Content-type: image/jpeg');// Output the imageimagejpeg($im);// Free up memoryimagedestroy($im);?>

Link to comment
Share on other sites

It's not going to output the URL in the image, there's nothing telling it do that. Are you sure it's an image you're looking at? If you right-click to save the image, and then double-click the saved image to open it, what do you see? Is that PHP code the only code you have on the page? Is there any other HTML or PHP code?

Link to comment
Share on other sites

I think you misunderstood my question.In your image generating PHP code, is that all the code there is? Is there any HTML or other PHP code inside that same script? If there is, it's probably causing a problem. If you have any blank lines outside of the PHP block that's probably going to cause a problem also.Like I said, try to pull up the image in a browser where you said you saw an image containing the URL of the script. Right-click on it and save the image, then find where you saved it and double-click on it to open it. See if you still see an image when it opens.You can also add this code to the top of your PHP code:error_reporting(E_ALL);ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log');ini_set('html_errors', 0);ini_set('log_errors', 1);ini_set('display_errors', 0);That will write all PHP errors to a file called error.log in the same directory as the script, if there are errors happening you can open that log file to see what they are.

Link to comment
Share on other sites

yeah, i missunderstood your question... ill try that.. thanks!. One small favor... do you mind if you give me some e mail address just in case I have some questions?... I rarely ask someone but I would like to have contact information of someone who knows more than me :).... thanks a lot!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...