PHP code example of yireo / magento2-webp2
1. Go to this page and download the library: Download yireo/magento2-webp2 library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yireo / magento2-webp2 example snippets
bash
#!/bin/bash
start=`date +%s`
directory="../pub/media"
cd "$directory" || exit
find . -type f \( -iname \*.jpg -o -iname \*.jpeg -o -iname \*.png \) -print0 |
while IFS= read -r -d $'\0' file;
do
filename=$(basename -- "$file")
new_filename="${filename%.*}.webp"
new_filepath="$(dirname "$file")/$new_filename"
echo "Converting: $file -> $new_filepath"
cwebp -q 80 -quiet "$file" -o "$new_filepath"
done
end=`date +%s`
runtime=$((end-start))
echo "Execution completed in $runtime seconds."