Invoke-Expression ".\bin\jpegoptim.exe -s `" $imageFullName `" " Write-Progress -Activity "Optimizing $imageName" -PercentComplete $percent -Status "jpegoptim" $percent = ( $imagesDone / $imagesTotal ) * 100 $imagesTotal = ($pngs.Length * 3) $jpgs.Length $jpgs = Get-ChildItem -Path $inputFolder -Include "*.jpg" -Recurse $pngs = Get-ChildItem -Path $inputFolder -Include "*.png" -Recurse # Source: # Binaries for jpegoptim # Binaries for OptiPNG # Binaries for Google's WebP # Binaryies for AVIF # Configuration I have it named web-image-optimizer.ps1, but the name doesn’t matter. cwebp.exe Binaries for libwebp (for cwebp).This PowerShell script depends on a handful of files to be downloaded and placed in a /bin folder: This means that even though you may intend to use only the lossy version of the image file on your site (JPG, WebP and AVIP) you should still export PNGs out of your design software so that WebP and AVIF files can be made by the script. We use PNG as the source file to create the other lossy formats (WebP and AVIF). If the file is a PNG, the script will losslessly optimize the PNG file in place to dramatically reduce the file size, but then it will also create both a WebP file and an AVIF file. If the file is a JPEG, the script will run jpegoptim to strip any unnecessary data and reduce the file size without harming the image quality. The script will search for all files within that folder, including all subfolders using the -Recurse attribute. The $inputFolder variable specifies the location of the input folder. The PowerShell script creates an array of all PNG and JPEG files in a folder. The script optimizes all PNG and JPEG files in place and converts the PNG files to WebP and AVIF. And because we are running a script, we can get some added benefits, too, such as making your PNG and JPEG files even smaller without any loss in quality.Īt Squirrel Logic, we’ve been using PowerShell scripts to prepare artwork for the web. The new AVIF image format, with its impressive results, is probably going to follow that same fate.īut there’s still a solution to easily getting your WebP and AVIF files. None of the major graphics applications support WebP, which has been around for a decade. I’m not optimistic, looking at recent history. With the launch of the AVIF image format, I’ve been seeing requests about AVIF support in Affinity Designer.
0 Comments
Leave a Reply. |