imagecreatefromgif() timing out

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

Post Reply
Zu
Forum Commoner
Posts: 33
Joined: Wed Dec 06, 2006 4:21 am

imagecreatefromgif() timing out

Post 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 :)
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post 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.
Zu
Forum Commoner
Posts: 33
Joined: Wed Dec 06, 2006 4:21 am

Post 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);
   }
}
Zu
Forum Commoner
Posts: 33
Joined: Wed Dec 06, 2006 4:21 am

Post by Zu »

Does anyone have any ideas?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
Post Reply