Skip to content

Instantly share code, notes, and snippets.

@hidonet
Created April 25, 2020 05:33
Show Gist options
  • Save hidonet/1596442208d89628ee3a58606bde604a to your computer and use it in GitHub Desktop.
Save hidonet/1596442208d89628ee3a58606bde604a to your computer and use it in GitHub Desktop.
Convert all webp images to jpeg
<?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