header('Content-Type: image/jpeg'); not behaving as I hoped.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: header('Content-Type: image/jpeg'); not behaving as I ho

Post by McInfo »

I have a theory. Run this diagnostic script on your localhost. My theory is that the path to bob.png is incorrect or that bob.png does not exist on your localhost. If the diagnostic script generates a black image, my theory is probably correct.

Code: Select all

<?php
$image = imagecreatetruecolor(300, 300);
header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
?>
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Tue Jun 15, 2010 10:42 pm, edited 1 time in total.
nickcherryjiggz
Forum Newbie
Posts: 9
Joined: Tue Jun 09, 2009 10:21 am

Re: header('Content-Type: image/jpeg'); not behaving as I hoped.

Post by nickcherryjiggz »

Dern. I was really hoping that I was just making a stupid mistake and mis-referencing the image. Unfortunately, not. :(

I ran this:

Code: Select all

<?php
$image = imagecreatetruecolor(300, 300);
header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
?>
And got this:

Code: Select all

The image “http://127.0.0.1:8000/jiggzyquick-startpackage/imagetest.php” cannot be displayed, because it contains errors.
And just for kicks, I also ran this:

Code: Select all

<?php
$image = imagecreatetruecolor(300, 300);
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
?>
And then got this:

Code: Select all

http://127.0.0.1:8000/jiggzyquick-startpackage/imagetest.php
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: header('Content-Type: image/jpeg'); not behaving as I hoped.

Post by mikemike »

What version of GD lib are you using?
nickcherryjiggz
Forum Newbie
Posts: 9
Joined: Tue Jun 09, 2009 10:21 am

Re: header('Content-Type: image/jpeg'); not behaving as I hoped.

Post by nickcherryjiggz »

Whatever came with the most recent version of MAMP, which looks to be "bundled (2.0.34 compatible)".

And for reference, my phpinfo() printout can be found at this URL:
http://www.jiggzy.com/phpinfo/

All the GD-related things seem to be enabled and it good shape.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: header('Content-Type: image/jpeg'); not behaving as I ho

Post by McInfo »

How attached are you to MAMP?

XAMPP for Mac OS X

Edit: This post was recovered from search engine cache.
Post Reply