Skip to content

Instantly share code, notes, and snippets.

@amorev
Last active May 24, 2021 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amorev/00cb6213fe15217a1e23987eb40a77da to your computer and use it in GitHub Desktop.
Save amorev/00cb6213fe15217a1e23987eb40a77da to your computer and use it in GitHub Desktop.
Convert webp images to png for work in safari
<?php
// details - https://amorev.ru/safari-webp-problem/
if ($handle = opendir('.')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
$fileInfo = explode('.', $entry);
$fileName = $fileInfo[0];
$fileExt = $fileInfo[1];
if ($fileExt === 'png') {
continue;
}
echo $entry;
exec('dwebp '.$entry.' -o '.$fileName.'.png', $a, $b);
if ($b != 0) {
echo 'not webp';
} else {
exec('convert '.$fileName.'.png '.$entry, $a, $b);
if ($b == 0) {
echo 'success';
}
}
echo PHP_EOL;
}
}
closedir($handle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment