note 126837 added to function.imagewebp
| From: | JSix at main dot php dot net | Date: | Wed, 09 Feb 2022 16:18:09 +0000 |
| Subject: | note 126837 added to function.imagewebp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217591@lists.php.net to get a copy of this message | ||
Function to save any image to Webp
public static function webpImage($source, $quality = 100, $removeOld = false)
{
$dir = pathinfo($source, PATHINFO_DIRNAME);
$name = pathinfo($source, PATHINFO_FILENAME);
$destination = $dir . DIRECTORY_SEPARATOR . $name . '.webp';
$info = getimagesize($source);
$isAlpha = false;
if ($info['mime'] == 'image/jpeg')
$image = imagecreatefromjpeg($source);
elseif ($isAlpha = $info['mime'] == 'image/gif') {
$image = imagecreatefromgif($source);
} elseif ($isAlpha = $info['mime'] == 'image/png') {
$image = imagecreatefrompng($source);
} else {
return $source;
}
if ($isAlpha) {
imagepalettetotruecolor($image);
imagealphablending($image, true);
imagesavealpha($image, true);
}
imagewebp($image, $destination, $quality);
if ($removeOld)
unlink($source);
return $destination;
}
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 195.245.244.51)
----
Manual Page -- https://php.net/manual/en/function.imagewebp.php
Edit -- https://main.php.net/note/edit/126837
Del: integrated -- https://main.php.net/note/delete/126837/integrated
Del: useless -- https://main.php.net/note/delete/126837/useless
Del: bad code -- https://main.php.net/note/delete/126837/bad+code
Del: spam -- https://main.php.net/note/delete/126837/spam
Del: non-english -- https://main.php.net/note/delete/126837/non-english
Del: in docs -- https://main.php.net/note/delete/126837/in+docs
Del: other reasons-- https://main.php.net/note/delete/126837
Reject -- https://main.php.net/note/reject/126837
Search -- https://main.php.net/manage/user-notes.php