loops/gif 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

loops/gif

Composer 安装命令:

composer require loops/gif

包简介

Unpacker/packer for GIF and especially animated GIF.

README 文档

README

Library used to parse/compile GIF files.

Requirements:

  • At least PHP 5.3.
  • Loops\Autoloader package.
  • Loops\Exception package.
  • Loops\Config package.

How to use it:

Autoloading

If you do not have composer, call bootstrap:

:::php
  require $path_to_package.'/bootstrap.inc.php';

This library use package-oriented autoloading with a directory for package namespace (PSR-4) and underscore as directory separator for class names (PSR-0).

GIF packs

A GIF pack represents a single part of GIF protocol block and sub-block. Pack names come from the GIF89a specifications, so be sure to be familiar with these specifications if you want to use this library efficiently.

Currently, this library can manage these kinds of GIF blocks:

  • Header
  • Logical Screen Descriptor
  • Global Color Table
  • Image Descriptor
  • Local Color Table
  • Table Based Image Data
  • Graphic Control Extension
  • Comment Extension
  • Plain Text Extension
  • Application Extension
  • Unknown Extension
  • Trailer
  • NETSCAPE 2.0 Application Extension (specific Application Extension)

Each pack can be parse or compile to a stream resource. Each pack may contains data, data names also come from the GIF89a specifications.

:::php
  // parse a Graphic Control Extension 
  $pack = new \Loops\Gif\Pack_GraphicControlExtension();
  // unpack from stream
  $pack->unpack( $stream );
  
  // then we can fetch data
  $pack->getData( 'Reserved' );
  $pack->getData( 'Disposal Method' );
  $pack->getData( 'User Input Flag' );
  $pack->getData( 'Transparent Color Flag' );
  $pack->getData( 'Delay Time' );
  $pack->getData( 'Transparent Color Index' );
  
  // compile a Image Descriptor
  $pack = new \Loops\Gif\Pack_ImageDescriptor();
  // assign all required data
  $pack->setData( 'Image Left Position' , 40 );
  $pack->setData( 'Image Top Position' , 20 );
  $pack->setData( 'Image Width' , 400 );
  $pack->setData( 'Image Height' , 200 );
  $pack->setData( 'Local Color Table Flag' , 0b1 );
  $pack->setData( 'Interlace Flag' , 0b0 );
  $pack->setData( 'Sort Flag' , 0b1 );
  $pack->setData( 'Reserved' , 0b01 );
  $pack->setData( 'Size of Local Color Table' , 0b101 );
  
  // then pack it to stream
  $pack->pack( $stream );

By convenience, to compile a pack, all data must be set.

Unpacker

The \Loops\Gif\Unpacker class is used to parse a GIF file/stream/binary and to return an array of GIF packs.

:::php
  $packs = \Loops\Gif\Unpacker::unpack( $file_or_stream_or_binary );

If you need to detect only if a certain block is present, a \Loops\Gif\Unpacker instance can be used. This instance will process packs on demand.

:::php
  $unpacker = \Loops\Gif\Unpacker::instance( $file_or_stream_or_binary );
  // is there at least two Image Descriptor (ie. animated GIF)
  $unpacker->hasPack( 'Image Descriptor' , 1 ); // first occurence is 0
  // GIF packs after this one have not been parsed yet
  
  // process only 5 packs
  $i = 5;
  while( $i-- )
  {
    // unpack current pack and go to next one
    $unpacker->next();
  }

The unpacking process may throws \Loops\Gif\Exception if the GIF data are corrupted.

Packer

The \Loops\Gif\Packer class is used to compile an array of GIF packs and to return binary data of the GIF.

:::php
  $binary = \Loops\Gif\Packer::pack( $array_of_packs );

You can also play with a \Loops\Gif\Packer instance to compile partially the array of packs.

:::php
  $packer = \Loops\Gif\Packer::instance( $array_of_packs );

  // process only 5 packs
  $i = 5;
  while( $i-- )
  {
    // pack current pack and go to next one
    $packer->next();
  }

The packing process may throw exceptions if packs are not in a correct order.

So, some important GIF specifications constraints must be respected in order to compile successfully an array of packs:

  • Header must be the first pack in the array, and nowhere else
  • Logical Screen Descriptor must be the second pack in the array, and nowhere else
  • Global Color Table must be the third pack in the array, and nowhere else, but only if the Logical Screen Descriptor claims that there is a Global Color Table (Global Color Table Flag)
  • Local Color Table can be present only after Image Descriptor, but only if the Image Descriptor claims that there is a Local Color Table (Local Color Table Flag)
  • Table Based Image Data can be present only after Local Color Table, or Image Descriptor if the Image Descriptor claims that there is no Local Color Table (Local Color Table Flag)

Contributors:

Wanna contribute?

There is only one rule to follow: Challenge yourself.

loops/gif 适用场景与选型建议

loops/gif 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「gif」 「animated gif」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 loops/gif 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 loops/gif 我们能提供哪些服务?
定制开发 / 二次开发

基于 loops/gif 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-07