Skip to content

Instantly share code, notes, and snippets.

@byBretema
Created February 21, 2024 21:58
Show Gist options
  • Save byBretema/93af961c61b55f6442b6b3d66bdf1414 to your computer and use it in GitHub Desktop.
Save byBretema/93af961c61b55f6442b6b3d66bdf1414 to your computer and use it in GitHub Desktop.
replace png images in all subfolders by webp
# install cwebp from: https://developers.google.com/speed/webp/docs/precompiled, and add it to $env:PATH
# 1- Conver png to web
(Get-ChildItem . -Recurse -File) | ForEach-Object { $src = "$($_.DirectoryName)\$($_.Name)"; if ($src.EndsWith(".png")) { $dst = $src.Replace(".png", ".webp"); cwebp -q 60 -o $dst $_; } }
# 2- Cleanup converted png files
(Get-ChildItem . -Recurse -File) | ForEach-Object { $src = "$($_.DirectoryName)\$($_.Name)"; if ($src.EndsWith(".png")) { Remove-Item $_ } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment