imagewebp CREATE a particular WebP image to be shown in a browser or stored in a file.
This function creates a WeBp file in $file from the $image which is created by imagecreate or imagecreatetruecolor, for example.
PALETTE IMAGE
is the designation term for images with a small number of colors.
For this type of image, a maximum of 256 colors are accepted.
TRUECOLOR IMAGE
is the designation term for images with a great number of colors.
For this type of image, a maximum of 16,777,216 colors are accepted.
This function returns TRUE on success or FALSE on failure.
However, if libgd fails to output the image, this function returns TRUE.
WebP
was first announced by Google on September 30, 2010 as a new open format for lossy compressed true-color graphics on the web, producing files that were smaller than JPEG files for comparable image quality.
It was based on technology that Google acquired with the purchase of On2 Technologies.
As a derivative of the VP8 video format, it is a sister project to the WebM multimedia container format.
WebP-related software is released under a BSD free software license.
On October 3, 2011, Google added an "Extended File Format" allowing WebP support for animation, ICC profile, XMP and Exif metadata, and tiling (compositing very large images from maximum 16384×16384 tiles).
Older animated GIF files can be converted to animated WebP.
On November 18, 2011, Google announced a new lossless compression mode, and support for transparency (alpha channel) in both lossless and lossy modes; support was enabled by default in libwebp 0.2.0 (August 16, 2012).
According to Google's measurements in November 2011, a conversion from PNG to WebP resulted in a 45% reduction in file size when starting with PNGs found on the web, and a 28% reduction compared to PNGs that are recompressed with pngcrush and PNGOUT
In July 2016, Apple added WebP support to early beta versions of macOS Sierra and iOS 10,but support was later removed in the GM seed versions of iOS 10 and macOS Sierra released in September 2016.
In September 2020, WebP support was added in Safari version 14.
The supporting libwebp library reached version 1.0 in April 2018.
As of May 2021, WebP was supported by 94% of the web browsers in use worldwide.
WebP's lossy compression algorithm is based on the intra-frame coding of the VP8 video format and the Resource Interchange File Format (RIFF) as a container format.
. . . . . .
From Wikipedia, the free encyclopedia.
<?php
bool imagewebp( GdImage $image,
resource|string|null $file = null,
int $quality = -1 )
where,
$image = The image identifier
$file = The path or stream resource
( SEE the below TABLE )
$quality = To control the quality
?>
$image
The image identifier returned exclusively by imagecreatetruecolor.
$file
The path or stream resource.
$file can reference a local file or, (configuration permitting), a remote file using one of the supported stream wrappers:
STREAM WRAPPERS |
MEANING |
file:// |
LOCAL File System |
http:// |
URL HTTP |
ftp:// |
URL FTP |
php:// |
I/O streams |
zlib:// |
Data Compression stream |
data:// |
DATA (RFC-2397) |
glob:// |
Find Filenames |
phar:// |
PHP Archive |
ssh2:// |
Secure Shell 2 |
rar:// |
RAR |
ogg:// |
Audio |
expect:// |
Interaction of stream processes |
ed48 |
$quality
The quality control.
QUALITY |
VALUE |
MEANING |
-1 |
QUALITY ABOUT 75% |
0 |
SMALLER QUALITY |
: : : : : : : : |
100 |
MAXIMUM QUALITY |
ed48 |
EXERCISE
<?php
echo 'PHP VERSION: ' . PHP_VERSION . '<br><br>';
$var = getcwd();
define ('PTW', 'file://' . $var . '/webp/');
echo PTW . '<br><br>';
$im01 = imagecreatetruecolor (200, 100);
$blue = imagecolorallocate($im01, 0, 0, 8);
$green = imagecolorallocate($im01, 0, 255, 0);
$img_file_stw = PTW . 'WEBP 001 01.webp';
// STREAM WRAPPER MODE
$img_file_nor = 'webp/WEBP 001 01.webp';
// NORMAL MODE
$quality01 = 60;
$bool01 = imagewebp($im01, $img_file_stw, $quality01);
if ($bool01 == TRUE)
{
$mess01 = 'The image was Created!';
echo '$bool01 = ';
var_dump($bool01);
echo '<br><br>' . $mess01;
echo '<br><br><img src="' . $img_file_nor .
'" alt="' . $img_file_nor . '" title="' . $img_file_nor . '">';
imagedestroy($im01);
}
else
{
$mess01 = 'The image COULD NOT BE CREATED!';
echo $mess01;
}
?>
RESULT WEBP 001 01.webpThe image has been created!
EXERCISE
<?php
// Try this code
echo 'PHP VERSION: ' . PHP_VERSION . '<br><br>';
$im02 = imagecreate (200, 100);
// ATENTION: PALETTE IMAGE
// ( See the error )
$blue = imagecolorallocate($im02, 0, 0, 8);
$green = imagecolorallocate($im02, 0, 127, 0);
$img_file_name = 'webp/WEBP 002 02.webp';
$quality02 = 60;
$bool02 = imagewebp($im02, $img_file_name, $quality02);
if ($bool02 == TRUE)
{
$mess02 = 'The image was Created!<br>';
echo '$bool02 = ';
var_dump($bool02);
echo '<br><br>' . $mess02;
echo '<br><br><img src="' . $img_file_name .
'" alt="' . $img_file_name . '" title="' . $img_file_name . '">';
imagedestroy($im02);
}
else
{
$mess02 = 'The image COULD NOT BE CREATED!';
echo $mess02;
}
?>
EXERCISE
<?php
// Try this code
echo 'PHP VERSION: ' . PHP_VERSION . '<br><br>';
$im03 = imagecreatetruecolor (200, 100);
$blue = imagecolorallocate($im03, 0, 0, 8);
$green = imagecolorallocate($im03, 0, 255, 0);
$img_file_name = null;
$quality03 = 60;
$bool03 = imagewebp($im03, $img_file_name, $quality03);
if ($bool03 == TRUE)
{
$mess03 = 'The image was Created!';
echo '<br><br>$bool03 = ';
var_dump($bool03);
echo '<br><br>' . $mess03;
echo '<br><br><img src="' . $img_file_name .
'" alt="' . $img_file_name . '" title="' . $img_file_name . '">';
imagedestroy($im03);
}
else
{
$mess03 = 'The image COULD NOT BE CREATED!';
echo $mess03;
}
?>