Page 1 of 1
imagecreatefromgif() timing out
Posted: Sun May 06, 2007 1:42 pm
by Zu
Okay, I am trying to manipulate an external image, however the script keeps timing out resulting in the file saying: "The image “uptime.gif” cannot be displayed, because it contains errors.". The image I am trying to load though imagecreatefromgif() is
http://www.webhostingstuff.com/uptimestatus/1.gif. I believe this image is generated dynamically.
So,
1) Even if it is dynamically generated, should imagecreatefromgif() still be able to process it?
2) If not, is there a way I can dymaically save it locally to use it that way?
3) Is it posible they have somehow, is posible, blocked this type of connection?
Thanks

Posted: Sun May 06, 2007 1:56 pm
by SidewinderX
Even if
http://www.webhostingstuff.com/uptimestatus/1.gif is generated dynamically, when it is displayed it is a static image so it really doesn't matter.
I've always received that error when I had faulty code. I'm sure if you post your code, someone could find the problem.
Posted: Sun May 06, 2007 2:06 pm
by Zu
I am pretty sure it isnt the code, I have tried it on numerous other images, such as Google's logo, and it works fine.
Code: Select all
<?php
/**
* Generated an overlay onto a template
* @author Zu
* @version 0.2
* @package ImageManipulation
*/
class GenerateOverlayImage
{
/**
* The URL of the original image
* @access private
* @var string
*/
private $originalLocation;
/**
* The URL of the template image
* @access private
* @var string
*/
private $templateLocation;
/**
* The overlay image
* @access private
* @var string
*/
private $overlay;
/**
* The template image
* @access private
* @var string
*/
private $template;
/**
* The final image
* @access private
* @var string
*/
private $image;
/**
* Class constructor
* @access public
*/
public function GenerateOverlayImage()
{
$this -> originalLocation = 'http://www.webhostingstuff.com/uptimestatus/1.gif';
$this -> templateLocation = 'template.gif';
$this -> generateOverlay();
$this -> generateTemplate();
}
/**
* Generates the overlay image
* @access private
*/
private function generateOverlay()
{
// Get the image, then get a small part of it
$tempImage = imagecreatefromgif($this -> originalLocation);
$crop = imagecreatetruecolor(75, 20);
// Shrink that small part of the image
imagecopy($crop, $tempImage, 0, 0,
40, 13,
75, 20);
imagecopyresampled($crop, $crop, 0, 0, 0, 0,
55, 20,
imagesx($crop),
imagesy($crop));
// Remove the unessecary excess from the crop
$this -> overlay = imagecreatetruecolor(55, 20);
imagecopy($this -> overlay, $crop, 0, 0,
0, 0,
55, 20);
imagepng($this -> overlay, 'uptime.png');
}
/**
* Generates the template image
* @access private
*/
private function generateTemplate()
{
// The overlay image
//$this -> overlay = imagecreatefrompng($this -> overlay);
$this -> overlay = imagecreatefrompng('uptime.png');
// The template image
$this -> template = imagecreatefromgif($this -> templateLocation);
// Create the basic graphic holder
$this -> image = imagecreatetruecolor(90, 50);
// Put the template in the image
imagecopyresampled($this -> image, $this -> template,
0, 0, 0, 0,
90, 50,
80, 50);
// Begin the overlaying
imagecopymerge($this -> image, $this -> overlay,
30, 12,
0, 0,
imagesx($this -> overlay), imagesy($this -> overlay),
99);
}
/**
* Returns the image
* @access public
* @return string overlayed template image
*/
public function getImage()
{
return imagepng($this -> image);
}
}
Posted: Mon May 07, 2007 5:25 am
by Zu
Does anyone have any ideas?
Posted: Mon May 07, 2007 5:48 am
by onion2k
"The image “uptime.gif” cannot be displayed, because it contains errors." is a browser error message. If you comment out the Content Type header and image output function (imagegif, imagejpeg, etc) from your script you'll see if PHP is outputting any other messages.