Last active
May 24, 2021 04:25
-
-
Save amorev/00cb6213fe15217a1e23987eb40a77da to your computer and use it in GitHub Desktop.
Convert webp images to png for work in safari
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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