Jump to content

Creating an image


amit_n

Recommended Posts

Hi,

 

I am trying to create a image. I am using WAMP and PHPinfo show GD is included. I have following code but i am not able to see the image. It displays the placeholder.

Code for picture1.php

 <?php
	$image = imagecreate(400,300);
    // do stuff to the image
    imagejpeg($image, '', 75);
    imagedestroy($image);
?> 

 

Code for phppicture.html

<HTML>
<TITLE>PHP Art</TITLE>
<BODY>
PHP woz 'ere:
<img src="picture1.php" />
</BODY>
</HTML> 

 

Please help me with this problem.

 

Thanks

Link to comment
Share on other sites

I suggest taking a look at the PHP imagejpeg documentation page, copy/paste examples are provided, like this one:

<?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/jpeg
header('Content-type: image/jpeg');

// Output the image
imagejpeg($im);

// Free up memory
imagedestroy($im);
?>

 

As you modify it and it stops displaying (not even an error) then comment the line

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

like this:

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

And errors should show up.

 

As soon as you fixed the errors and the only output you're getting looks like gibberish, then uncomment the header line again and you should see the image again.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.