encode() public method

Encode data into GIF hex string.
public encode ( array $data ) : string
$data array The array returned by decode.
return string Hex string of GIF
Example #1
0
 /**
  * Save the image to an image format.
  *
  * @param Image $image
  * @param string $file File path where to save the image.
  * @param null|string $type Type of image. Can be null, "GIF", "PNG", or "JPEG".
  * @param null|string $quality Quality of image. Applies to JPEG only. Accepts number 0 - 100 where 0 is lowest and 100 is the highest quality. Or null for default.
  * @param bool|false $interlace Set to true for progressive JPEG. Applies to JPEG only.
  * @param int $permission Default permission when creating non-existing target directory.
  *
  * @return Editor
  * @throws \Exception
  */
 public function save($image, $file, $type = null, $quality = null, $interlace = false, $permission = 0755)
 {
     if (null === $type) {
         $type = $this->_getImageTypeFromFileName($file);
         // Null given, guess type from file extension
         if (ImageType::UNKNOWN === $type) {
             $type = $image->getType();
             // 0 result, use original image type
         }
     }
     $targetDir = dirname($file);
     // $file's directory
     if (false === is_dir($targetDir)) {
         // Check if $file's directory exist
         // Create and set default perms to 0755
         if (!mkdir($targetDir, $permission, true)) {
             throw new \Exception(sprintf('Cannot create %s', $targetDir));
         }
     }
     switch (strtoupper($type)) {
         case ImageType::GIF:
             if ($image->isAnimated()) {
                 $blocks = $image->getBlocks();
                 $gift = new GifHelper();
                 $hex = $gift->encode($blocks);
                 file_put_contents($file, pack('H*', $hex));
             } else {
                 imagegif($image->getCore(), $file);
             }
             break;
         case ImageType::PNG:
             // PNG is lossless and does not need compression. Although GD allow values 0-9 (0 = no compression), we leave it alone.
             imagepng($image->getCore(), $file);
             break;
         default:
             // Defaults to jpeg
             $quality = $quality === null ? 75 : $quality;
             // Default to 75 (GDs default) if null.
             $quality = $quality > 100 ? 100 : $quality;
             $quality = $quality < 0 ? 0 : $quality;
             imageinterlace($image->getCore(), $interlace);
             imagejpeg($image->getCore(), $file, $quality);
     }
     return $this;
 }