GD displays garbage as though header incorrect

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

GD displays garbage as though header incorrect

Postby Iowarth » Sun Mar 15, 2009 4:15 pm

I have an image script I have been using successfully for some years on one server. The full version actually extracts the image address from a database and writes a watermark on the image. The script is called as an <img src by another page.
On a second site on another server it delivered gibberish as though "header" command not set. I was able to resolve this by using "while (@ob_end_clean());" before the header command.
For another website I am helping to rebuild, the same problem has arisen - but the cure doesn't work!
I have reduced the code to an irreducible minimum just in case a problem lurked elsewhere in the script but the error is repeated.
The garbage output is the typical "�����JFIF���������>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality
���C� 

 $.' ",#(7),01444'9=82<.342���C 

2!!22222222222222222222222222222222222222222222222222�����"��������������
4. �������}�!1AQa"q2���#B��R��$3br�

The basic code (which works on other servers) between the php tags is:-
1. $image=ImageCreateFromJpeg("20090312wart019001.jpg");
2. while (@ob_end_clean());
3. header('Content-Type: image/jpeg');
4. imagejpeg($image);
No spaces, returns etc before or after
This has got me totally beat - any assistance much appreciated. You can access the file at http://www.wartsoc.co.uk/gallery/image.php
Thanks again
Iowarth
Iowarth
Forum Newbie
 
Posts: 6
Joined: Sun Mar 15, 2009 3:59 pm

Re: GD displays garbage as though header incorrect

Postby omniuni » Mon Mar 16, 2009 12:01 am

Put $header ='Content-type: image/jpeg'; BEFORE you do ImageCreateFromJpeg and let me know if that works for ya.

-OmniUni
User avatar
omniuni
Forum Regular
 
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: GD displays garbage as though header incorrect

Postby Iowarth » Mon Mar 16, 2009 2:30 am

Hi OmniUni

Thanks for your input. I had already tried your suggestion in the more complete script with no effect. I have, nevertheless, tried it again with the short script and absolutely no difference. Page definitely appears as though the header isn't working still.
Although irrelevant to your input I should perhaps have mentioned that this is the same in all browsers (IE6 & 7, Firefox 2 & 3, Opera, Google Chrome and Safari) and appears to be server specific.
I would also add that although I have left while (@ob_end_clean()) in the code it serves no purpose in this instance as php output_buffering has no value set. Nevertheless, its appearance or absence make no difference!
Yours in desperation
Iowarth
Iowarth
Forum Newbie
 
Posts: 6
Joined: Sun Mar 15, 2009 3:59 pm

Re: GD displays garbage as though header incorrect

Postby omniuni » Mon Mar 16, 2009 1:47 pm

Can you post the complete code please? As long as the header is the ABSOLUTE first thing to come out of the script, it SHOULD work just fine. Maybe there is a clue elsewhere. Oh, just to check the obvious, did you check the permissions of the file?
User avatar
omniuni
Forum Regular
 
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: GD displays garbage as though header incorrect

Postby Iowarth » Tue Mar 17, 2009 2:37 am

Hi again omniuni
The problem isn't with the rest of the coding. The coding as given works perfectly well on all my other servers. It can be seen, for example, at http://79.170.40.231/captive-bred-repti ... image2.php - with exactly the same image. Images on all servers are set at rw-r-r. The identical coding can be seen at http://www.wartsoc.co.uk/gallery/image2.php where it generates the problem. Similarly the problem is not with the image which can be accessed directly at http://www.wartsoc.co.uk/gallery/20090312wart019001.jpg. Similarly there is no obvious GD problem as images are resized (twice) by GD when uploading - and this, of course, uses both the GD commands present in this file. So, the problem seems to somehow related to the header function. But how this might be has got me completely beat. I am completely at my wit's end!
Regards
Iowarth
Iowarth
Forum Newbie
 
Posts: 6
Joined: Sun Mar 15, 2009 3:59 pm

Re: GD displays garbage as though header incorrect

Postby omniuni » Tue Mar 17, 2009 3:36 am

Iowarth, well, the good news is that a hex editor reveals that your script is indeed dealing with the image as it should. The server and your test are both using the same GD versions, and one would think they are using the same headers.

Now for the bad news; your headers are not correct.

Check this out; the headers delivered for the working copy:
HTTP/1.x 200 OK
Date: Tue, 17 Mar 2009 08:25:40 GMT
Server: Apache/2
X-Powered-By: PHP/4.4.9
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: image/jpeg


And from the unworking copy:
HTTP/1.x 200 OK
Date: Tue, 17 Mar 2009 08:25:37 GMT
Server: Apache
X-Powered-By: PHP/5.2.8
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html


See? content type is text/html!

I have my own image script that resizes images for me which you can see here:
http://omniimpact.com/snippet_resources ... &square=60
I am using PHP 5.2.6, and it works just fine, so it SHOULD be POSSIBLE.

Have you contacted your host, to see what they can tell you about the problem?

My guess is that like something I did myself before, there is something in the rest of the code that is outputting before the header. It is possible that the exact same code will react differently because you are going from a PHP 4.4.9 to 5.2.8, a much newer version!

Just for kicks and giggles, take that header() line OUT of the rest of the code, and just stick it right up there at the very top of the file. Just after the PHP tags open.
User avatar
omniuni
Forum Regular
 
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: GD displays garbage as though header incorrect

Postby Iowarth » Tue Mar 17, 2009 5:39 pm

Hi Omniuni
Thanks for your further help which at least confirms exactly what I thought was happening WAS happening! I have since tried the identical code on another server which is running the same version of PHP (5.2.8) and it works perfectly. Changing the header position made no difference either!
So, I have sent an email to the ISP's support setting out the problem, symptoms etc and asked if their server setting are responsible. I am pretty sure they are - but also pretty sure that they won't be of much help!
Heigh ho!
Thanks again
iowarth
Iowarth
Forum Newbie
 
Posts: 6
Joined: Sun Mar 15, 2009 3:59 pm

Re: GD displays garbage as though header incorrect

Postby Iowarth » Mon Mar 23, 2009 6:01 pm

Hi Omniuni
Well, I have been in an endless chain of correspondence with the relevant ISP. They persisted in pointing out alleged faults with the script and I persisted in pointing out to them that their proposed changes made no difference at all (apart from occasionally making it worse!)
I investigated further and found that precisely this fault could be caused by Apache Modlayout - documented in this forum link http://www.usenet-forums.com/php-langua ... peg-3.html
I advised them of this and queried whether this might be the problem but they kept trying to maintain it was the script.
Today, after their latest response on these lines I sent a blistering response and then, just because it was open (and showing the usual gobbledegook) clicked "Refresh" and it worked! There were three other variations up there, trying their suggestions, none of which had worked and all of which suddenly and mysteriously did work!!
I can't prove it, but have a sneaking suspicion it was mod_layout and that they put in an exception for the gallery without mentioning it! In all fairness, they did put themselves out but I did feel that they never read what I said until the very end!
Anyway - problem solved even if I can't be 100% certain how!
Iowarth
Iowarth
Forum Newbie
 
Posts: 6
Joined: Sun Mar 15, 2009 3:59 pm

Re: GD displays garbage as though header incorrect

Postby omniuni » Thu Mar 26, 2009 6:27 pm

I'm glad the problem is solved, but if the host treats you like that, I recommend that you leave them. A host should never treat you so that you feel dumb, or insist that they are right, and you are wrong, if they can't fix the problem. One of the things I have loved about my host is that they always will admit when they have been part of the problem, and they usually will do everything they can to fix it. If there is something odd going on, they have been known to directly fix the offending files. (I was having some php.ini issues, and they gave me a full copy of their php.ini along with the corresponding modifications that were required, and some directions on what items they needed to change)

Good luck!
User avatar
omniuni
Forum Regular
 
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: GD displays garbage as though header incorrect

Postby Iowarth » Thu Mar 26, 2009 6:51 pm

I agree 100% Omniuni. Sadly, I was only sorting this site as a favour and have no control over where they host it. Having said that - your hosting service sounds even better than mine - who are they might I ask?
Iowarth
Iowarth
Forum Newbie
 
Posts: 6
Joined: Sun Mar 15, 2009 3:59 pm

Re: GD displays garbage as though header incorrect

Postby nabob » Mon Sep 12, 2011 12:07 am

hi all,


As am installing GDCHART application with GD

but i cant enable gdchart in php...it shows an error class not found.


help me

regards,

nabob
nabob
Forum Newbie
 
Posts: 5
Joined: Sun Sep 11, 2011 11:59 pm


Return to PHPGD.com

Who is online

Users browsing this forum: No registered users and 1 guest