This extension allows Zopfli compression.
Documentation for Zopfli can be found at » https://github.com/google/zopfli.
% git submodule update --init
% phpize
% ./configure
% make
$ make install
php.ini:
extension=zopfli.so
- 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
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.
-
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.
The encoded string, or FALSE if an error occurred.
string zopfli_compress ( string $data [, int $iteration = 15 ] )
This function compress the given string using the ZLIB data format.
-
data
The data to compress.
-
iteration
The iteration of compression. Specify a value greater than 0.
The compressed string or FALSE if an error occurred.
string zopfli_deflate ( string $data [, int $iteration = 15 ] )
This function compress the given string using the DEFLATE data format.
-
data
The data to deflate.
-
iteration
The iteration of compression. Specify a value greater than 0.
The deflated string or FALSE if an error occurred.
string zopfli_decode ( string $data [, int $length = 0 ] )
This function returns a decoded version of the input data.
same as gzdecode().
-
data
The data to decode, encoded by zopfli_encode(), gzencode().
-
length
The maximum length of data to decode.
The decoded string, or FALSE if an error occurred.
string zopfli_uncompress ( string $data [, int $length = 0 ] )
This function uncompress a compressed string.
same as gzuncompress().
-
data
The data compressed by zopfli_compress(), gzcompress().
-
length
The maximum length of data to decode.
The original uncompressed data or FALSE on error.
string zopfli_inflate ( string $data [, int $length = 0 ] )
This function inflate a deflated string.
same as gzinflate().
-
data
The data compressed by zopfli_deflate(), gzdeflate().
-
length
The maximum length of data to decode.
The original uncompressed data or FALSE on error.
string zopfli_png_recompress ( string $data [, int $iteration = 15 ] )
This function recompresses IDAT chunks in a PNG Image.
-
data
The PNG Image
-
iteration
The iteration of compression. Specify a value greater than 0.
The recompressed PNG Image or FALSE on error.
$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);