Grafika\Gd\Helper\GifHelper::isAnimated PHP Method

isAnimated() public method

public isAnimated ( GifByteStream $bytes ) : boolean
$bytes GifByteStream
return boolean
    public function isAnimated($bytes)
    {
        $bytes->setPosition(13);
        $lastPos = $bytes->getPosition();
        $gceCount = 0;
        while (($lastPos = $bytes->find('21f904', $lastPos)) !== false) {
            $gceCount++;
            if ($gceCount > 1) {
                return true;
            }
        }
        return false;
    }

Usage Example

Beispiel #1
0
 /**
  * Load a GIF image.
  *
  * @param string $imageFile
  *
  * @return Image
  * @throws \Exception
  */
 private static function _createGif($imageFile)
 {
     $gift = new GifHelper();
     $bytes = $gift->open($imageFile);
     $animated = $gift->isAnimated($bytes);
     $blocks = '';
     if ($animated) {
         $blocks = $gift->decode($bytes);
     }
     $gd = @imagecreatefromgif($imageFile);
     if (!$gd) {
         throw new \Exception(sprintf('Could not open "%s". Not a valid %s file.', $imageFile, ImageType::GIF));
     }
     return new self($gd, $imageFile, imagesx($gd), imagesy($gd), ImageType::GIF, $blocks, $animated);
 }