Date
Dec. 11th, 2024
 
2024年 11月 11日

Post: Script for Optimizing Images

Script for Optimizing Images

Published 14:02 Feb 13, 2023.

Created by @ezra. Categorized in #UNIX/Linux, and tagged as #Arch Linux, #UNIX/Linux, #Ubuntu Linux.

Source format: Markdown

Table of Content

Sample Script

Optimizing images is easy with this script! Img-optimizer + ImageMagicK leverages multiple CLI tools to give the best results.

#!/bin/bash
# Dependencies
# - img-optimize - https://virtubox.github.io/img-optimize/
# - imagemagick
# - jpegoptim
# - optipng

for file in *.png; do convert "$file" -verbose -resize 600\> "$file"; done
img-optimize --std --path "$(pwd)"

Dependencies

  • imagemagick
  • opting
  • jpegoptim

Debian Command

sudo apt install jpegoptim optipng imagemagick webp -y
git clone https://github.com/VirtuBox/img-optimize.git $HOME/.img-optimize
sudo ln -s $HOME/.img-optimize/optimize.sh /usr/local/bin/img-optimize
sudo chmod +x /usr/local/bin/img-optimize

Arch Command

yay -S jpegoptim opting imagemagick webp -y
git clone https://github.com/VirtuBox/img-optimize.git $HOME/.img-optimize
sudo ln -s $HOME/.img-optimize/optimize.sh /usr/local/bin/img-optimize
sudo chmod +x /usr/local/bin/img-optimize

Custom Script

#!/bin/bash
# Dependancies
# - img-optimize - https://virtubox.github.io/img-optimize/
# - imagemagick
# - jpegoptim
# - optipng

FOLDER="/home/ezra/ecs/website/content/images"

# max width
WIDTH=800

# max height
HEIGHT=600

#resize png or jpg to either height or width, keeps proportions using imagemagick
find ${FOLDER} -iname '*.jpg' -o -iname '*.png' -exec convert \{} -verbose -resize $WIDTHx$HEIGHT\> \{} \;
img-optimize --std --path ${FOLDER}
Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
开发、设计与写作皆为所长。
热爱苹果、钟情色彩。
随时恭候 垂询