|
1 |
| -# Image optimization bash script |
2 |
| - |
3 |
| - |
4 |
| - |
5 |
| -[](https://travis-ci.org/VirtuBox/img-optimize)     |
6 |
| - |
7 |
| -## Prerequisite |
8 |
| - |
9 |
| -- jpegoptim for jpg optimization |
10 |
| -- optipng for png optimization |
11 |
| -- cwebp for WebP conversion |
12 |
| - |
13 |
| -### From APT repositories |
14 |
| - |
15 |
| -Debian/Ubuntu : |
16 |
| - |
17 |
| -```bash |
18 |
| -sudo apt install jpegoptim optipng webp -y |
19 |
| -``` |
20 |
| - |
21 |
| -Centos 7 : |
22 |
| - |
23 |
| -```bash |
24 |
| -sudo yum install optipng jpegoptim libwebp-tools -y |
25 |
| -``` |
26 |
| - |
27 |
| -### Compile the latest release (optipng & libwebp) |
28 |
| - |
29 |
| -For Debian/Ubuntu (available in scripts folder) : |
30 |
| - |
31 |
| -```bash |
32 |
| -# optipng |
33 |
| -curl -sL git.io/fjddn | sudo -E bash |
34 |
| - |
35 |
| -# libwebp |
36 |
| -curl -sL git.io/fjdd6 | sudo -E bash |
37 |
| -``` |
38 |
| - |
39 |
| --------------------------------------------------------------------------------- |
40 |
| - |
41 |
| -## Installation |
42 |
| - |
43 |
| -1) Clone the repository |
44 |
| - |
45 |
| -```bash |
46 |
| -git clone https://github.com/VirtuBox/img-optimize.git $HOME/.img-optimize |
47 |
| -``` |
48 |
| - |
49 |
| -2) Install the script |
50 |
| - |
51 |
| -**Method 1** : Add an alias in .bashrc |
52 |
| - |
53 |
| -With this method img-optimize can only be used by the current user |
54 |
| - |
55 |
| -```bash |
56 |
| -echo "alias img-optimize=$HOME/.img-optimize/optimize.sh" >> $HOME/.bashrc |
57 |
| -source $HOME/.bashrc |
58 |
| -``` |
59 |
| - |
60 |
| -**Method 2** : Add an alias to the script in /usr/local/bin |
61 |
| - |
62 |
| -With this method img-optimize can be used by all users |
63 |
| - |
64 |
| -```bash |
65 |
| -sudo ln -s $HOME/.img-optimize/optimize.sh /usr/local/bin/img-optimize |
66 |
| -sudo chmod +x /usr/local/bin/img-optimize |
67 |
| -``` |
68 |
| - |
69 |
| -## Usage |
70 |
| - |
71 |
| -```bash |
72 |
| -Bash script to optimize your images and convert them in WebP |
73 |
| -Usage: img-optimize [options] <images path> |
74 |
| -If images path isn't defined, img-optimize will use the current directory |
75 |
| - Options: |
76 |
| - --jpg <images path> ..... optimize all jpg images |
77 |
| - --png <images path> ..... optimize all png images |
78 |
| - --webp <images path> ..... convert all images in webp |
79 |
| - --nowebp <images path> ..... optimize all png & jpg images |
80 |
| - --all <images path> ..... optimize all images (png + jpg + webp) |
81 |
| - -i, --interactive ..... run img-optimize in interactive mode |
82 |
| - -q, --quiet ..... run image optimization quietly |
83 |
| - Other options : |
84 |
| - -h, --help, help ... displays this help information |
85 |
| -Examples: |
86 |
| - optimize all jpg images in /var/www/images |
87 |
| - img-optimize --jpg /var/www/images |
88 |
| -``` |
89 |
| -
|
90 |
| -## Update the script |
91 |
| -
|
92 |
| -To update the script, just run : |
93 |
| -
|
94 |
| -```bash |
95 |
| -git -C $HOME/.img-optimize pull |
96 |
| -``` |
97 |
| -
|
98 |
| -## Setup daily cronjob |
99 |
| -
|
100 |
| -You just have to copy the scripts to /etc/cron.daily : |
101 |
| -
|
102 |
| -```bash |
103 |
| -cp $HOME/.img-optimize/crons/jpg-png-cron.sh /etc/cron.daily/jpg-png-cron |
104 |
| -cp $HOME/.img-optimize/crons/jpg-png-cron.sh /etc/cron.daily/webp-cron |
105 |
| -
|
106 |
| -chmod +x /etc/cron.daily/jpg-png-cron |
107 |
| -chmod +x /etc/cron.daily/webp-cron |
108 |
| -``` |
109 |
| -
|
110 |
| -Then just edit your websites path set with the variables `sites` at the beginning of the cron scripts. |
111 |
| -
|
112 |
| -## Warning |
113 |
| -
|
114 |
| -Conversion process can take a while, you can use `tmux` to launch the script and be able to close your ssh connection without interrupting conversion. Then just use `tmux attach` to login back in your tmux session. |
115 |
| -
|
116 |
| -## Credits |
117 |
| -
|
118 |
| -- WebP conversion script was inspired by this [DigitalOcean Community Tutorial](https://www.digitalocean.com/community/tutorials/how-to-create-and-serve-webp-images-to-speed-up-your-website) |
119 |
| -
|
120 |
| -- Tutorial about webp conversion available on [jesuisadmin.fr](https://jesuisadmin.fr/convertir-vos-images-en-webp-nginx/) (in french) |
| 1 | +# Image optimization bash script |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +[](https://travis-ci.org/VirtuBox/img-optimize)     |
| 6 | + |
| 7 | +## Prerequisite |
| 8 | + |
| 9 | +- jpegoptim for jpg optimization |
| 10 | +- optipng for png optimization |
| 11 | +- cwebp for WebP conversion |
| 12 | +- go-avif for Avif conversion |
| 13 | + |
| 14 | +### From APT repositories |
| 15 | + |
| 16 | +Debian/Ubuntu : |
| 17 | + |
| 18 | +```bash |
| 19 | +sudo apt install jpegoptim optipng webp -y |
| 20 | +``` |
| 21 | + |
| 22 | +Centos 7 : |
| 23 | + |
| 24 | +```bash |
| 25 | +sudo yum install optipng jpegoptim libwebp-tools -y |
| 26 | +``` |
| 27 | + |
| 28 | +### Compile the latest release (optipng & libwebp) |
| 29 | + |
| 30 | +For Debian/Ubuntu (available in scripts folder) : |
| 31 | + |
| 32 | +```bash |
| 33 | +# optipng |
| 34 | +curl -sL git.io/fjddn | sudo -E bash |
| 35 | + |
| 36 | +# libwebp |
| 37 | +curl -sL git.io/fjdd6 | sudo -E bash |
| 38 | +``` |
| 39 | + |
| 40 | +### Go-Avif installation |
| 41 | + |
| 42 | +```bash |
| 43 | +sudo wget -qO /usr/local/bin/avif https://github.com/Kagami/go-avif/releases/download/v0.1.0/avif-linux-x64 |
| 44 | +sudo chmod +x /usr/local/bin/avif |
| 45 | +``` |
| 46 | + |
| 47 | +-------------------------------------------------------------------------------- |
| 48 | + |
| 49 | +## Installation |
| 50 | + |
| 51 | +1) Clone the repository |
| 52 | + |
| 53 | +```bash |
| 54 | +git clone https://github.com/VirtuBox/img-optimize.git $HOME/.img-optimize |
| 55 | +``` |
| 56 | + |
| 57 | +2) Install the script |
| 58 | + |
| 59 | +**Method 1** : Add an alias in .bashrc |
| 60 | + |
| 61 | +With this method img-optimize can only be used by the current user |
| 62 | + |
| 63 | +```bash |
| 64 | +echo "alias img-optimize=$HOME/.img-optimize/optimize.sh" >> $HOME/.bashrc |
| 65 | +source $HOME/.bashrc |
| 66 | +``` |
| 67 | + |
| 68 | +**Method 2** : Add an alias to the script in /usr/local/bin |
| 69 | + |
| 70 | +With this method img-optimize can be used by all users |
| 71 | + |
| 72 | +```bash |
| 73 | +sudo ln -s $HOME/.img-optimize/optimize.sh /usr/local/bin/img-optimize |
| 74 | +sudo chmod +x /usr/local/bin/img-optimize |
| 75 | +``` |
| 76 | + |
| 77 | +## Usage |
| 78 | + |
| 79 | +```bash |
| 80 | +Bash script to optimize your images and convert them in WebP |
| 81 | +Usage: img-optimize [options] <images path> |
| 82 | +If images path isn't defined, img-optimize will use the current directory |
| 83 | + Options: |
| 84 | + --jpg ..... optimize all jpg images |
| 85 | + --png ..... optimize all png images |
| 86 | + --webp ..... convert all images in webp |
| 87 | + --avif ..... convert all images in avif |
| 88 | + --std ..... optimize all png & jpg images |
| 89 | + --next ..... convert all images in webp & avif |
| 90 | + --all ..... optimize all images (png + jpg + webp + avif) |
| 91 | + -i, --interactive ..... run img-optimize in interactive mode |
| 92 | + -q, --quiet ..... run image optimization quietly |
| 93 | + --path <images path> ..... define images path |
| 94 | + Other options : |
| 95 | + -h, --help, help ... displays this help information |
| 96 | + --cmin [+|-]<n> ... File's status was last changed n minutes ago. |
| 97 | + act find cmin argument (+n : greater than n, -n : less than n, n : exactly n) |
| 98 | +Examples: |
| 99 | + optimize all jpg images in /var/www/images |
| 100 | + img-optimize --jpg --path /var/www/images |
| 101 | +``` |
| 102 | + |
| 103 | +### Update the script |
| 104 | + |
| 105 | +To update the script, just run : |
| 106 | + |
| 107 | +```bash |
| 108 | +git -C $HOME/.img-optimize pull |
| 109 | +``` |
| 110 | + |
| 111 | +### Setup daily cronjob |
| 112 | + |
| 113 | +You just have to copy the scripts to /etc/cron.daily : |
| 114 | + |
| 115 | +```bash |
| 116 | +cp $HOME/.img-optimize/crons/jpg-png-cron.sh /etc/cron.daily/jpg-png-cron |
| 117 | +cp $HOME/.img-optimize/crons/jpg-png-cron.sh /etc/cron.daily/webp-cron |
| 118 | + |
| 119 | +chmod +x /etc/cron.daily/jpg-png-cron |
| 120 | +chmod +x /etc/cron.daily/webp-cron |
| 121 | +``` |
| 122 | + |
| 123 | +Then just edit your websites path set with the variables `sites` at the beginning of the cron scripts. |
| 124 | + |
| 125 | +## Warning |
| 126 | + |
| 127 | +Conversion process can take a while, you can use `tmux` to launch the script and be able to close your ssh connection without interrupting conversion. Then just use `tmux attach` to login back in your tmux session. |
| 128 | + |
| 129 | +## Credits |
| 130 | + |
| 131 | +- WebP conversion script was inspired by this [DigitalOcean Community Tutorial](https://www.digitalocean.com/community/tutorials/how-to-create-and-serve-webp-images-to-speed-up-your-website) |
| 132 | + |
| 133 | +- Tutorial about webp conversion available on [jesuisadmin.fr](https://jesuisadmin.fr/convertir-vos-images-en-webp-nginx/) (in french) |
0 commit comments