aboutsummaryrefslogtreecommitdiff
path: root/src/blog
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2023-03-06 22:44:29 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2023-03-06 22:44:29 +0100
commit1daea33eec09c376b09739e204bee480f7bf4140 (patch)
tree77e6cfa2902c675465407750f48a7c5af4ac711b /src/blog
parent5b4f601fc74a1ed607fb93fea7cabc4cc3a1f5ba (diff)
downloadsebastiano.tronto.net-1daea33eec09c376b09739e204bee480f7bf4140.tar.gz
sebastiano.tronto.net-1daea33eec09c376b09739e204bee480f7bf4140.zip
Finished blog post
Diffstat (limited to 'src/blog')
-rw-r--r--src/blog/2023-03-06-resize-pictures/resize-pictures.md79
1 files changed, 59 insertions, 20 deletions
diff --git a/src/blog/2023-03-06-resize-pictures/resize-pictures.md b/src/blog/2023-03-06-resize-pictures/resize-pictures.md
index c28340f..e7e7f18 100644
--- a/src/blog/2023-03-06-resize-pictures/resize-pictures.md
+++ b/src/blog/2023-03-06-resize-pictures/resize-pictures.md
@@ -12,39 +12,39 @@ $ du -h -d 1 sebastiano.tronto.net
12225M sebastiano.tronto.net 12225M sebastiano.tronto.net
13``` 13```
14 14
15Stupid modern phones and their multi-megapixel cameras! 15Stupid modern phones and their multi-megapixel cameras! I definitely
16I definitely do not want my minimalist blog to waste your bandwidth, 16do not want my minimalist blog to waste your bandwidth, I have to fix
17I have to fix this. I could just go through all my pictures and resize 17this. I could just go through all my pictures and resize them one by
18them with something like [gimp](https://www.gimp.org/) - there are like 18one with something like [gimp](https://www.gimp.org/) - there are like
1910 of them. But that's boring. Let's do it with the command line instead. 1910 of them. But that's boring. Let's do it with the command line instead!
20 20
21## ImageMagick 21## ImageMagick
22 22
23The obvious question is: how do we even edit an image file 23The obvious question is: how do we even edit a picture
24with the command line? Luckily, there is a tool for that: 24with the command line? Luckily, there is a tool for that:
25[ImageMagick](https://imagemagick.org/). This piece of software 25[ImageMagick](https://imagemagick.org/). This piece of software can do a
26does a ton of things, and I do not use it very often. So I always 26ton of things, and I do not use it very often, so I always need to look
27need to look up what I want to do. 27up what I want to do.
28 28
29One way to invoke ImageMagick is by calling the `convert` command, 29One way to invoke ImageMagick is by
30which can take a 30calling the `convert` command, which can take a
31[`-resize`](https://imagemagick.org/script/command-line-options.php#resize) 31[`-resize`](https://imagemagick.org/script/command-line-options.php#resize)
32option, followed by a 32option, followed by a
33[`geometry`](https://imagemagick.org/script/command-line-processing.php#geometry) 33[`geometry`](https://imagemagick.org/script/command-line-processing.php#geometry)
34argument. After checking the online manual, I understood that the 34argument. After checking the online manual, I understood that the command
35command I was looking for was: 35I was looking for was:
36 36
37``` 37```
38$ convert picture.jpg -resize "750>" picture.jpg 38$ convert picture.jpg -resize "750>" picture.jpg
39``` 39```
40 40
41which resizes `picture.jpg` by scaling it down to at most 750px width - 41which resizes `picture.jpg` by scaling it down to at most 750px width -
42keeping the ratio between width and height, and leaving it untouched if it 42preserving the ratio between width and height, and leaving the picture
43is already smaller. The value 750 was chosen after a couple of attempts, 43untouched if it is already smaller. The value 750 was chosen after a
44it seems a good compromise between quality and size. 44couple of attempts, it seems a good compromise between quality and size.
45 45
46And now I just have to do this for all the pictures. Of course, running 46And now I just have to do this for all pictures. Of course, running the
47the same command 10 times with a different argument is out of question. 47same command 10 times with a different argument is out of question.
48 48
49## find(1) 49## find(1)
50 50
@@ -58,7 +58,7 @@ running a command). The OpenBSD and GNU versions of find have some
58differences, check your local manual page. The commands I use 58differences, check your local manual page. The commands I use
59here have been tested on the GNU version, but should be standard. 59here have been tested on the GNU version, but should be standard.
60 60
61To look for file and simply print their name, we can use `-name`: 61To look for files and simply print their name, we can use `-name`:
62 62
63``` 63```
64$ find src -name \*.jpg -or -name \*.png 64$ find src -name \*.jpg -or -name \*.png
@@ -75,12 +75,51 @@ src/blog/2023-02-25-job-control/jobs-diagram.png
75src/blog/2022-12-30-blog-ready/pc-planner.jpg 75src/blog/2022-12-30-blog-ready/pc-planner.jpg
76``` 76```
77 77
78Notice how I had to escape the `*`: the strings `\*.jpg` and `\*.png`
79are part of the find command, we don't want the shell to expand them.
80
78Now we can use `-exec` to run a command on each of these files, 81Now we can use `-exec` to run a command on each of these files,
79using `{}` to refer to the file's name: 82using `{}` to refer to the file's name:
80 83
81``` 84```
82find src \( -name \*.jpg -or -name \*.png \) -exec convert {} -resize "750>" {} \; 85$ find src \( -name \*.jpg -or -name \*.png \) -exec convert {} -resize "750>" {} \;
83``` 86```
84 87
85We get a couple of warnings about grayscale images, but whatever. 88We get a couple of warnings about grayscale images, but whatever.
86This seems to have worked. 89This seems to have worked.
90
91## The weight of history
92
93Let's see if things have improved:
94
95```
96$ du -h -d 1 sebastiano.tronto.net
9719M sebastiano.tronto.net/gemini
9819M sebastiano.tronto.net/http
9919M sebastiano.tronto.net/src
100102M sebastiano.tronto.net/.git
101158M sebastiano.tronto.net
102```
103
104That's... a bit disappointing. It looks like large pictures were not
105the only culprit - all the [slides for my math talks](../../research)
106are also quite heavy. Too bad, I am not going to change them now.
107Maybe in a follow-up post :-)
108
109Just like me with my old slides, git also wants to keep a memory
110of the past. After all, this is what version control system are
111supposed to do. If you are wondering why my website is a git
112repository, check out
113[this old blog post of mine](../2022-08-14-website). In the end,
114I don't really need the ability to revert my website to an older
115version, so I could just reset the repo from all the history
116at some point.
117
118## Conclusion
119
120ImageMagick is and find are both powerful tools. I am happy with looking
121up ImageMagick's syntax everytime, but I definitely want to become more
122proficient with find.
123
124This was not a hard task, but I have learned something new. I hope you
125did too :-)

Generated with cgit - Back to sebastiano.tronto.net