Created
April 25, 2020 05:33
-
-
Save hidonet/1596442208d89628ee3a58606bde604a to your computer and use it in GitHub Desktop.
Convert all webp images to jpeg
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 | |
$media_path = './media/catalog/product'; | |
$files = []; | |
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($media_path)); | |
foreach ($rii as $file) | |
{ | |
if ($file->isDir()){ continue;} | |
$files[] = $file->getPathname(); | |
} | |
$cnt = 0; | |
$total = count($files); | |
foreach ($files as $file) | |
{ | |
$cnt++; | |
$file_content = file_get_contents($file); | |
if (strpos($file_content, 'WEBPVP8')) | |
{ | |
$im = imagecreatefromwebp($file); | |
imagejpeg($im, $file, 100); | |
imagedestroy($im); | |
echo $cnt."/".$total." - WEBP -- ".$file."\n"; | |
} // if sonu | |
else | |
{ | |
echo $cnt."/".$total." - ORJ -- ".$file."\n"; | |
} // else sonu | |
//if ($cnt == 100) {break;} // if sonu | |
} // foreach sonu | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment