#images
14 one-liners with this tag.
All one-liners tagged images
Convert images to AVIF recursively
$find /var/www/vhosts/example.com/httpdocs/wp-content/uploads -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' \) -exec sh -c 'for f; do [ -e "$f.avif" ] || avifenc -s 6 "$f" "$f.avif" >/dev/null; done' sh {} +
Convert images to WebP recursively
$find /var/www/vhosts/example.com/httpdocs/wp-content/uploads -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' \) -exec sh -c 'for f; do [ -e "$f.webp" ] || cwebp -quiet -q 80 "$f" -o "$f.webp"; done' sh {} +
Find images larger than a given pixel size
$find /var/www/vhosts/example.com/httpdocs/wp-content/uploads -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' \) -exec identify -format '%w %h %i\n' {} + 2>/dev/null | awk -v max=2560 '$1 > max || $2 > max'
Find images without a loading attribute on a page
$curl -s https://example.com/ | tr '\n' ' ' | grep -oiE '<img[^>]*>' | grep -vi 'loading='
Find images without an alt attribute on a page
$curl -s https://example.com/ | tr '\n' ' ' | grep -oiE '<img[^>]*>' | grep -viE '\balt='
Find large images in wp-content/uploads
$find /var/www/vhosts/example.com/httpdocs/wp-content/uploads -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.gif' -o -iname '*.webp' \) -size +500k -printf '%s\t%p\n' | sort -rn | head -50 | numfmt --field=1 --to=iec
Limit JPEG quality to a maximum with jpegoptim
$find /var/www/vhosts/example.com/httpdocs/wp-content/uploads -type f \( -iname '*.jpg' -o -iname '*.jpeg' \) -exec jpegoptim --strip-all --preserve --max=82 {} +
Optimize JPEG images losslessly with jpegoptim
$find /var/www/vhosts/example.com/httpdocs/wp-content/uploads -type f \( -iname '*.jpg' -o -iname '*.jpeg' \) -exec jpegoptim --strip-all --preserve {} +
Optimize PNG images losslessly with optipng
$find /var/www/vhosts/example.com/httpdocs/wp-content/uploads -type f -iname '*.png' -exec optipng -o2 -strip all -preserve {} +
Regenerate missing thumbnails
$wp media regenerate --only-missing --yes --path=/var/www/vhosts/example.com/httpdocs
Remove dangling Docker images
#docker image prune
Remove EXIF and other metadata from images
$exiftool -r -ext jpg -ext jpeg -all= -overwrite_original /var/www/vhosts/example.com/httpdocs/wp-content/uploads
Resize large images to a maximum size with mogrify
$find /var/www/vhosts/example.com/httpdocs/wp-content/uploads -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' \) -exec mogrify -resize '2560x2560>' {} +
Shrink PNG images lossily with pngquant
$find /var/www/vhosts/example.com/httpdocs/wp-content/uploads -type f -iname '*.png' -exec pngquant --quality=65-85 --skip-if-larger --strip --force --ext .png {} +