PHP script not always displaying image
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- PHP script not always displaying image
PHP script not always displaying image
25-12-2007 12:01 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
http://ccgi.pabs2003.plus.com/petimage/rosa.jpg
You should see an image of a the tarantula in your browser (i hope you're not aracnophobic). So far so good, right, ....
Now, before I add the resizing code I've done a simple PHP script to display the image for now:
<?php
header("Content-type: image/jpeg");
$image = imagecreatefromjpeg('http://ccgi.pabs2003.plus.com/petimage/rosa.jpg');
imagejpeg($image);
?>
Later on I will hopefully add resizing code, but for now my main concern is that this script does not always result in the image displaying on my browser all the time.
Try it yourself:
http://ccgi.pabs2003.plus.com/cgi-bin/Pets/imagejpeg.php
To see what I mean click the 'Refresh' button on and wait. Do that a couple of times.
I find that I get the image around 50-60% of time, and the rest of the time the browser just waits forever.
Why doesn't it always work?

Someone please take a look at this problem for me. I'd really appreciate it.
Thank you!
Merry Christmas,
Pablo.
Re: PHP script not always displaying image
25-12-2007 10:56 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
<?php
header("Content-type: image/jpeg");
$image = imagecreatefromjpeg('http://ccgi.pabs2003.plus.com/petimage/rosa.jpg');
if(!$image){
echo "Image creation failed";
} else {
imagejpeg($image);
imagedestroy($image);
}
?>
At least it'll give a bit more of an insight into if it's being created on those times that you don't see it working.
Merry Xmas

Re: PHP script not always displaying image
25-12-2007 12:54 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
ok I've tried altering the code to that, but i still get the same result.
on my browser i just get 'Waiting for ccgi.pabs2003.plus.com' at the bottom and the spinning 'loading' icon goes on forever. when i hit 'refresh' it might work or it might not, either way i get no error.
i might get lucky and it loads first time around, but then it will always fail at some point, quite soon, if i keep refreshing.
Just out of interest here is the link:-
http://ccgi.pabs2003.plus.com/cgi-bin/Pets/imagejpeg.php
although i think i already gave it to you.
Thanks a lot!!
Merry Christmas,
Pablo.
Re: PHP script not always displaying image
25-12-2007 4:55 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
jelv (a.k.a Spoon Whittler) Why I have left Plusnet (warning: long post!) Broadband: Andrews & Arnold Home::1 (FTTC 80/20) Line rental: Pulse 8 Home Line Rental (£14.40/month) Mobile: iD mobile (£4/month) |
Re: PHP script not always displaying image
25-12-2007 6:07 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
i tried it at work today with IE7 and at home with Opera 9.25 -- tbhe resize deosn't work at all in opera
Re: PHP script not always displaying image
25-12-2007 6:23 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator

Does it only happen with this one page, or multiple different pages (in particular pages that do not use the imagecreatefromjpeg function)?
SNIP: Just wrote a heap of code for you, but decided I should test it first and it turns out it's useless. I'll have a closer look at it tomorrow.
Re: PHP script not always displaying image
25-12-2007 9:49 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Sorry didn't get back to you sooner. Families and that, you know

I created a new file with the following code, as adviced:
<?php
header("Content-type: image/jpeg");
$image = imagecreatetruecolor(400,400);
if(!$image){
echo "Image creation failed";
} else {
imagejpeg($image);
imagedestroy($image);
}
?>
See it at:-
http://ccgi.pabs2003.plus.com/cgi-bin/Pets/imagejpeg2.php
And guess what? It works.
You were right!
Pablo.
Re: PHP script not always displaying image
26-12-2007 12:03 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Re: PHP script not always displaying image
26-12-2007 2:35 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Sorry didn't get back to you sooner. Went out skateboarding.
I don't know how i would do it without imagecreatefromjpeg(). I'm stuck at this point in time.
Thanks for all your help.
Take care,
Pablos.
Re: PHP script not always displaying image
26-12-2007 3:23 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Re: PHP script not always displaying image
26-12-2007 3:56 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
I still can't really understand why it isn't working sometimes and working others. Writing up some code now which, if it works, will at least help debugging a bit. It's a hard one to diagnose though, since I've never came across it before.
Re: PHP script not always displaying image
26-12-2007 4:00 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
That's true, i could let the browser resize the image, but then i would also be forcing the browser to download a potentially very large image - that's what I'm trying to avoid. I was thinking the only other possibility would be to let the PHP resize the image upon the user uploading a thumbnail the image, but then that still leaves the possibility of imagecreatefromjpeg() not working (*), and that would be very uncooperative thing.
Thanks!!
Pablos.
* it seems that is what stopped the image loading
imagecreatefromjpeg() is times-out; was: PHP script not always displaying image
04-01-2008 7:30 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
I have found that PHP's processing of the document containing a call to the GD library function imagecreatefromjpeg() hangs-up on that line and simply goes no further (*). I tried various strategies, including reducing the .jpg image to very-small image in case that was the problem, and trying other jpeg sources but the results were the same.
Having done some research on Google I found that there were a few people who were having this problem and the advice given to them seems to have been to report it to PHP.net as a bug.
Hypothetically if this *is* a bug then it seems to have been fixed in later versions of GD/PHP, but in the mean-time i'm stuck because the version of PlusNet's GD/PHP has a bug --assuming that to be the problem.
I don't think there is a work-around for this. Is there any other option other than to change to an ISP that provides a better version of GD/PHP?
Please advice.
All the best,
Pablos.
* sometimes it works fine, but more often than not it just hangs-up
mystery solved: why wasn't imagecreatefromjpeg() working -- doh!!
07-01-2008 7:02 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Over Christmas I posted here to ask why my script using the imagecreatefromjpeg() function wasn't working.
Cut a long story short, I want to thank all of you who tried to help me. In particular thanks to Mr Mike Whitehead who inspite of his hangover very kindly volunteered to help me and nearly found the problem. Thanks, Mike, for that.
Thing is I didn't know, and seems nobody else spotted either, was that you weren't supposed to call imagecreatefromjpeg() using a filename parameter as an HTTP request, so I had something like the following, from memory:-
imagecreatefromjpeg('http://ccgi.pabs2003.plus.com/petimage/rosa.jpg");
and no matter how much I tried to work it it kept failing now and again, but I always kept using 'http://.....' as a parameter, that was the reason.
Now thanks to Mr Richard Pearce in PlusNet Technical support I know that I am being a bad boy doing this. You are supposed to use the file-system for this call, so somthing like the following works no problem:0
imagecreatefromjpeg('rosa.jpg');
where my convoluted 'http://....' parameters where not working.
Don't know why I did it this way. I think i must have believed that jpeg files were not accessible on the cgi web space so I had to muddle-around using an 'http://....' call to the image instead, and it worked..... kind of.
Thanks a lot guys.
All the best,
Pablo.
Re: PHP script not always displaying image
07-01-2008 10:37 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Back when I was a customer, so your talking about 3 years back, more so, back prior to the current incarnation of the CCGI server (when it was just called CGI, or criticalmass).
I spotted that if you wanted to load a URL from the CGI server, it would fail. Now normally this doesn't matter, as you can do it different ways, just as pipe the output from the shell, include it if it is PHP (or same lang as the calling code) or a few other tricks.
What you could not do however was use something like an XML or news feed from another site hosted on the CGI server, which could only be done by the URL.
When looking into it, the load balancer basically does not like loopback connections. ie, it cannot handle a connection from the CGI server to the CGI servers load balancer IP.
It could however handle a connection to the servers local IP address and if clever enough, fool the CGI server to serve content as if it was a normal web request.
I created some code so that PHP could handle a custom URI, just for use on the CGI server, such as cgi://cgi.username.plus.com/site.php
I no longer have a copy, though there may be somebody about with one. I am unsure if it works in the new CCGI setup, but it is essentially the same issues preventing your original code working.
If there is a copy about, I will clean it up and ensure it works on the servers.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- PHP script not always displaying image