This extension allows Zopfli compression.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

Zopfli Extension for PHP

Build Status

This extension allows Zopfli compression.

Documentation for Zopfli can be found at » https://github.com/google/zopfli.

Build

% git submodule update --init
% phpize
% ./configure
% make
$ make install

Configration

zopfli.ini:

extension=zopfli.so

Function

  • zopfli_encode — Create a gzip compressed string
  • zopfli_compress — Compress a string
  • zopfli_deflate — Deflate a string
  • zopfli_decode — Decodes a gzip compressed string
  • zopfli_uncompress — Uncompress a compressed string
  • zopfli_inflate — Inflate a deflated string
  • zopfli_png_recompress — Recompress IDAT chunks in a PNG Image

zopfli_encode — Create a gzip compressed string

Description

string zopfli_encode ( string $data [, int $iteration = 15 [, int $encoding = ZOPFLI_GZIP ]] )

This function returns a compressed version of the input data compatible with the output of the gzip program.

Parameters

  • data

    The data to encode.

  • iteration

    The iteration of compression. Specify a value greater than 0.

  • encoding

    The encoding mode. Can be ZOPFLI_GZIP (the default) or ZOPFLI_DEFLATE, ZOPFLI_ZLIB.

Return Values

The encoded string, or FALSE if an error occurred.

zopfli_compress — Compress a string

Description

string zopfli_compress ( string $data [, int $iteration = 15 ] )

This function compress the given string using the ZLIB data format.

Parameters

  • data

    The data to compress.

  • iteration

    The iteration of compression. Specify a value greater than 0.

Return Values

The compressed string or FALSE if an error occurred.

zopfli_deflate — Deflate a string

Description

string zopfli_deflate ( string $data [, int $iteration = 15 ] )

This function compress the given string using the DEFLATE data format.

Parameters

  • data

    The data to deflate.

  • iteration

    The iteration of compression. Specify a value greater than 0.

Return Values

The deflated string or FALSE if an error occurred.

zopfli_decode — Decodes a gzip compressed string

Description

string zopfli_decode ( string $data [, int $length = 0 ] )

This function returns a decoded version of the input data.

same as gzdecode().

Pameters

  • data

    The data to decode, encoded by zopfli_encode(), gzencode().

  • length

    The maximum length of data to decode.

Return Values

The decoded string, or FALSE if an error occurred.

zopfli_uncompress — Uncompress a compressed string

Description

string zopfli_uncompress ( string $data [, int $length = 0 ] )

This function uncompress a compressed string.

same as gzuncompress().

Parameters

  • data

    The data compressed by zopfli_compress(), gzcompress().

  • length

    The maximum length of data to decode.

Return Values

The original uncompressed data or FALSE on error.

zopfli_inflate — Inflate a deflated string

Description

string zopfli_inflate ( string $data [, int $length = 0 ] )

This function inflate a deflated string.

same as gzinflate().

Parameters

  • data

    The data compressed by zopfli_deflate(), gzdeflate().

  • length

    The maximum length of data to decode.

Return Values

The original uncompressed data or FALSE on error.

zopfli_png_recompress — Recommress IDAT chunks in PNG Image

Description

string zopfli_png_recompress ( string $data [, int $iteration = 15 ] )

This function recompresses IDAT chunks in a PNG Image.

Parameters

  • data

    The PNG Image

  • iteration

    The iteration of compression. Specify a value greater than 0.

Return Values

The recompressed PNG Image or FALSE on error.

Examples

$data = zopfli_encode('test');

zopfli_decode($data);
//gzdecode($data);

$data = zopfli_compress('test');

zopfli_uncompress($data);
//gzuncompress($data);

$data = zopfli_deflate('test');

zopfli_inflate($data);
//gzinflate($data);

$data = file_get_contents('original.png');
$recompress = zopfli_png_recompress($data);
file_put_contents('recompress.png', $recompress);

Related