Jump to content

The Image Cannot Be Displayed, Because It Contains Errors.


tal

Recommended Posts

Hello peoplei am trying to display an image with GD functions, but i am having problems what i have done is i have two files: html file that "calls" a php file when i run my html file it gives me this - " hy there "and when i run my php file directly i get this error - "The image “http://site/image.php” cannot be displayed, because it contains errors."i have the two files below as they are, and they are all in the same folder even pic1.gif what am i missing ?have i forgot anything ?i am using php 5.3.0i have the "extension=php_gd2.dll" enabled Apache 2.2.11on windows xpand mozila firefoxthank youTalhtml file ----------<html> <head> <title>image problem</title> </head> <body> <img src="image.php" /> hy there </body></html>image.php------------<?phpheader("Content-type: image/gif");$im = ImageCreateFromGIF("pic1.gif");imagegif($im);imagedestroy($im);?>

Link to comment
Share on other sites

The imagecreatefromgif() function has no uppercase letters in it.

Link to comment
Share on other sites

What's your code now? Does pic1.gif exist in the same directory?

Link to comment
Share on other sites

Remove this line:

header("Content-type: image/gif");

and then access the file directly in your browser to see if PHP is outputting any error messages.

Link to comment
Share on other sites

hy Ingolmei removed "header("Content-type: image/gif");"and insted of an error i get thisfor example-"GIF89a*\ȰÇ#JHŋ3j"and a full screen of things like it i looked at my html file but no image appeared i am new to working with images so what does that mean (except not giving an error)(by the way errors are enabled in my php configuration)thank you for helpingTal

Link to comment
Share on other sites

I've just tried your coding and it works fine, with or without header("Content-type: image/gif");My GD settings are below, also i have read about when upload/downloading file, if it is not transferred as binary file, it may not be able to read the image file as it should.GD Support enabled GD Version bundled (2.0.34 compatible) FreeType Support enabled FreeType Linkage with freetype FreeType Version 2.1.9 T1Lib Support enabled GIF Read Support enabled GIF Create Support enabled JPG Support enabled PNG Support enabled WBMP Support enabled XBM Support enabled

Link to comment
Share on other sites

hy dsonesukif so it must be some thing wrong with my configuration this is from my phpinfo(), it seams i have a newer "FreeType Version 2.3.9"what installation of php did you get if i remember correct i did the - php-5.3.0-Win32-VC6-x86.msidid a new install not long ago could it be some thing with "HTTP Headers Information "i got the settings below also from my phpinfo()thanks for the tip about upload/downloading file, as binary, i will remember that when the time comes but does using the GD library counts as upload/download, it is all done on my local computerthanks for helpingTalGD Support enabledGD Version bundled (2.0.34 compatible)FreeType Support enabledFreeType Linkage with freetypeFreeType Version 2.3.9GIF Read Support enabledGIF Create Support enabledJPEG Support enabledlibJPEG Version 6bPNG Support enabledlibPNG Version 1.2.37WBMP Support enabledXBM Support enabledDirectivegd.jpeg_ignore_warning------------------------------------------------HTTP Request Headers------------------------HTTP Request GET /Sites/show%20my%20info.php HTTP/1.1Host hostnameUser-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language en-us,en;q=0.5Accept-Encoding gzip,deflateAccept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7Keep-Alive 300Connection keep-aliveReferer http://Sites/HTTP Response Headers----------------------------X-Powered-By PHP/5.3.0Keep-Alive timeout=5, max=96Connection Keep-AliveTransfer-Encoding chunkedContent-Type text/html

Link to comment
Share on other sites

Make sure your image.php file does not have extra whitespace - you should have no spaces or blank lines before the starting PHP tag or after the ending PHP tag. The data that is outputted by a function like imagegif is binary data, if you have a line break before that you're adding ASCII data to the binary data, and it's going to mess up the stream that the browser expects.

Link to comment
Share on other sites

The version of PHP i use is 5.2.6. gd.jpeg_ignore_warning is not listed. the listing that mentions images are as followsPHP Variables _SERVER["HTTP_ACCEPT"] image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */* HTTP Request Headers HTTP Request : GET /phpinfo.php HTTP/1.1Accept : image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*Accept-Language : en-gbUA-CPU : x86Accept-Encoding : gzip, deflateUser-Agent : Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)Host : localhostConnection : Keep-AliveHTTP Response Headers X-Powered-By : PHP/5.2.6Keep-Alive : timeout=5, max=100Connection : Keep-AliveTransfer-Encoding : chunkedContent_Type : text/htmlThe download/upload relates to the uploading of files to web server using FTP, as it should be uploaded as a type 'binary', but i can't see as this would be a problem, as you are running this from your local computer.

Link to comment
Share on other sites

well my phpinfo() looks poor compering to yours :)_SERVER["HTTP_ACCEPT"] text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8HTTP Request Headers------------------------Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8in the apache httpd.conf i have looked at DefaultType diractive, and mime_moduleand in the php.ini i have looked at default_mimetypebut didn't find out how to manage the http request headers :)can you help me with that ?p.slooking around for how to manage these configuration i found a nice site http://www.askapache.com/thank you Tal

Link to comment
Share on other sites

The headers don't have anything to do with this, the request headers are the headers that your browser sent to the server when it asked for the PHPinfo page. The headers that your browser sent don't have anything to do with whether or not PHP is going to output an image in the correct format. Check for extra whitespace in the PHP file.

Link to comment
Share on other sites

hy justsomeguyyou really help all around i have checked my image.php file for white spaces (and found none)even got all of the commands on one line to make surethanks for the clerefication about the header request and i thought i got the problem there with the headers thank you for helpingTal

Link to comment
Share on other sites

So this script does not work for you:

<?phpheader("Content-type: image/gif");$im = ImageCreateFromGIF("pic1.gif");imagegif($im);imagedestroy($im);?>

Do you have an image called pic1.gif in the same directory as the script?

Link to comment
Share on other sites

There's a problem with GIF output that I haven't found a reason for. This works when I use imagepng or imagejpeg to output the image, but it doesn't like imagegif. If dsonesuk did try it and it worked, then it must not be the GD version since both of you have the same. I have 2.0.28 and see the same behavior as you. I'm doing this on a Windows server. I'll upload to a Linux server to test there as well and check the versions.GIF output works correctly on a Linux server with GD 2.0.34.Are you running this on a Windows machine?

Link to comment
Share on other sites

hy justsomeguyyes i have all the files image.php, test.html, (pic1.gif, pic1.png, pic1.jpg, pic1.jpeg) in the same folder i am working on a windows machine i have tried it with all the image types above with the corosponding functions and they are all the same on my computerall give me a blank picture (actually there is that red dot on the top left corner :))i have seen a few examples that use @imagecreatefrompng (with @ before the function) and few that do not (could it make a difference)<?phpheader("Content-type: image/png");$im = imagecreatefrompng(pic1.png);imagepng($im);imagedestroy($im);?>could it be some thing with the headers already sent to the browser for the <head> and <body> of my test.html file and because of that (the browser already got headers) it can not get the image headers ?Tal

Link to comment
Share on other sites

The @ operator just suppresses warning messages if they happen. I was able to run this on my Windows server:

<?phpheader("Content-type: image/png");$im = imagecreatefromgif("pic1.gif");imagepng($im);imagedestroy($im);?>

So I opened the GIF, but outputted a PNG image. That worked fine, it also worked fine when I outputted a JPG. Only outputting a GIF was having problems, but on a Linux server it was working fine.

could it be some thing with the headers
I don't think so, not if the PHP code you're posting is the only thing you have inside image.php. These are the response headers from the server when I open image.php and try to output a GIF:
Connection: closeDate: Tue, 04 Aug 2009 21:54:23 GMTServer: Microsoft-IIS/6.0X-Powered-By: ASP.NET, PHP/5.2.0Content-Type: image/gif

These are the headers when I go directly to pic1.gif:

Content-Length: 4025Content-Type: image/gifLast-Modified: Tue, 04 Aug 2009 19:00:18 GMTAccept-Ranges: bytesEtag: "f657fdce3515ca1:fa1"Server: Microsoft-IIS/6.0X-Powered-By: ASP.NETDate: Tue, 04 Aug 2009 21:55:04 GMT

The Last-Modified header doesn't matter. PHP is sending a connection header, but that shouldn't cause a problem. That just tells the browser that the connection is going to be closed after the response ends. The accept-ranges header is optional and doesn't even apply to this request. The etag header looks like it's supposed to uniquely identify the resource on the server, but again that doesn't come in to play for this request. Content length is always optional, that's just how the browser shows the progress bar when it's downloading something.So, I don't think the headers are the problem. The headers from the Linux server where it works aren't much different.

$im = imagecreatefrompng(pic1.png);
That line has a syntax error, you need to quote the filename.
Link to comment
Share on other sites

when running it with a png,gif i get the error The image “http://Sites/image.php” cannot be displayed, because it contains errors.but when running it with jpg,jpeg i get the image.php path http://Sites/image.phpeither way i dont see a picture on screen both give me no errors in error.log and access.log similer to this test.html HTTP/1.1" 304 -image.php HTTP/1.1" 200 2480do you understand anything new from that maybe telling apache to handle *.php as images (that probably make more harm then good)thanksTal

Link to comment
Share on other sites

I think i have found what is causing the error, the image is saved as CMYK instead of RGB.In short, CMYK is intended for print and RGB is intended for screen. because is has 4 values (Cyan, Magenta, Yellow, Black) it is capable of producing many more color variations than RGB (Red Green Blue). i saved the file as CMYK, and got exact error message (photoshop -> image -> mode) resaved as RGB problem gone!

Link to comment
Share on other sites

I'm using gimp, I don't even see a CMYK option there. I tried a couple random gifs we had sitting around though. Can you post one that works so I can check it here? This seems pretty inconsistent, it sounds like a bug but I can't find any info on it. This is the only bug I can find that seems to be related:http://bugs.php.net/bug.php?id=39082But that's in a release candidate for PHP 5.2, and was fixed. I did give imagegif a filename, and it did successfully save to a new image that I was able to open. There seems to be a problem outputting it to the browser though.e.g. imagegif($im, 'pic2.gif');

Link to comment
Share on other sites

I'm sort of seeing the same behavior still, neither of the images show up here as GIF output, but they both show up as PNG output. With GIF output, the image on the left shows a broken image link, and the image on the right shows no image link. So there does seem to be an issue with CMYK GIF output, but they do both still work as PNG output.

Link to comment
Share on other sites

would this be because you don't have the decoding and encoding of images for gif types, as supplied by photoshop? similar to fonts, if you don't have specific font displayed on website, it will show an alternative instead, from fonts available from users O/S Arial, verdana etc.

Link to comment
Share on other sites

As far as I'm aware, CMYK settings are only stored and used in PSD files, since no other applications or formats have any support for CMYK format.The setting that GIF files use is "indexed," which means that it has a defined and limited color palette. Just to make sure, I just opened your "CMYK" gif file and it is set to "indexed" as opposed to CMYK.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...