From 5b4f601fc74a1ed607fb93fea7cabc4cc3a1f5ba Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 6 Mar 2023 22:24:32 +0100 Subject: Resized images + blog post --- src/blog/2022-09-10-netbooks/darkstar.jpg | Bin 3578876 -> 155458 bytes src/blog/2022-09-10-netbooks/final.jpg | Bin 6089913 -> 224546 bytes src/blog/2022-09-10-netbooks/hd.jpg | Bin 5031032 -> 197080 bytes src/blog/2022-09-10-netbooks/scramble.jpg | Bin 4134845 -> 206364 bytes src/blog/2022-12-30-blog-ready/pc-planner.jpg | Bin 6497789 -> 203907 bytes src/blog/2023-01-28-windows-desktop/settings.png | Bin 43045 -> 69520 bytes src/blog/2023-01-28-windows-desktop/tiling.png | Bin 68884 -> 27650 bytes src/blog/2023-02-25-job-control/jobs-diagram.png | Bin 56672 -> 37996 bytes .../2023-03-06-resize-pictures/resize-pictures.md | 86 +++++++++++++++++++++ src/blog/blog.md | 1 + src/blog/feed.xml | 7 ++ src/favicon.png | Bin 8829 -> 4828 bytes src/me.png | Bin 223247 -> 226377 bytes src/speedcubing/cubing.png | Bin 813446 -> 721767 bytes 14 files changed, 94 insertions(+) create mode 100644 src/blog/2023-03-06-resize-pictures/resize-pictures.md diff --git a/src/blog/2022-09-10-netbooks/darkstar.jpg b/src/blog/2022-09-10-netbooks/darkstar.jpg index 3d32dd1..fb736dd 100644 Binary files a/src/blog/2022-09-10-netbooks/darkstar.jpg and b/src/blog/2022-09-10-netbooks/darkstar.jpg differ diff --git a/src/blog/2022-09-10-netbooks/final.jpg b/src/blog/2022-09-10-netbooks/final.jpg index 63b33bf..7789e14 100644 Binary files a/src/blog/2022-09-10-netbooks/final.jpg and b/src/blog/2022-09-10-netbooks/final.jpg differ diff --git a/src/blog/2022-09-10-netbooks/hd.jpg b/src/blog/2022-09-10-netbooks/hd.jpg index 525726b..dcc84b5 100644 Binary files a/src/blog/2022-09-10-netbooks/hd.jpg and b/src/blog/2022-09-10-netbooks/hd.jpg differ diff --git a/src/blog/2022-09-10-netbooks/scramble.jpg b/src/blog/2022-09-10-netbooks/scramble.jpg index 0d9cb5f..e9c6017 100644 Binary files a/src/blog/2022-09-10-netbooks/scramble.jpg and b/src/blog/2022-09-10-netbooks/scramble.jpg differ diff --git a/src/blog/2022-12-30-blog-ready/pc-planner.jpg b/src/blog/2022-12-30-blog-ready/pc-planner.jpg index 8fb52e5..dc7d803 100644 Binary files a/src/blog/2022-12-30-blog-ready/pc-planner.jpg and b/src/blog/2022-12-30-blog-ready/pc-planner.jpg differ diff --git a/src/blog/2023-01-28-windows-desktop/settings.png b/src/blog/2023-01-28-windows-desktop/settings.png index 85ec492..84bd2c2 100644 Binary files a/src/blog/2023-01-28-windows-desktop/settings.png and b/src/blog/2023-01-28-windows-desktop/settings.png differ diff --git a/src/blog/2023-01-28-windows-desktop/tiling.png b/src/blog/2023-01-28-windows-desktop/tiling.png index dd1f3ec..ef28431 100644 Binary files a/src/blog/2023-01-28-windows-desktop/tiling.png and b/src/blog/2023-01-28-windows-desktop/tiling.png differ diff --git a/src/blog/2023-02-25-job-control/jobs-diagram.png b/src/blog/2023-02-25-job-control/jobs-diagram.png index 484e7b9..d61a769 100644 Binary files a/src/blog/2023-02-25-job-control/jobs-diagram.png and b/src/blog/2023-02-25-job-control/jobs-diagram.png differ diff --git a/src/blog/2023-03-06-resize-pictures/resize-pictures.md b/src/blog/2023-03-06-resize-pictures/resize-pictures.md new file mode 100644 index 0000000..c28340f --- /dev/null +++ b/src/blog/2023-03-06-resize-pictures/resize-pictures.md @@ -0,0 +1,86 @@ +# Resizing my website's pictures with ImageMagick and find(1) + +I have noticed that most of the pictures I have uploaded on this website +are incredibly large: + +``` +$ du -h -d 1 sebastiano.tronto.net +42M sebastiano.tronto.net/gemini +42M sebastiano.tronto.net/http +42M sebastiano.tronto.net/src +100M sebastiano.tronto.net/.git +225M sebastiano.tronto.net +``` + +Stupid modern phones and their multi-megapixel cameras! +I definitely do not want my minimalist blog to waste your bandwidth, +I have to fix this. I could just go through all my pictures and resize +them with something like [gimp](https://www.gimp.org/) - there are like +10 of them. But that's boring. Let's do it with the command line instead. + +## ImageMagick + +The obvious question is: how do we even edit an image file +with the command line? Luckily, there is a tool for that: +[ImageMagick](https://imagemagick.org/). This piece of software +does a ton of things, and I do not use it very often. So I always +need to look up what I want to do. + +One way to invoke ImageMagick is by calling the `convert` command, +which can take a +[`-resize`](https://imagemagick.org/script/command-line-options.php#resize) +option, followed by a +[`geometry`](https://imagemagick.org/script/command-line-processing.php#geometry) +argument. After checking the online manual, I understood that the +command I was looking for was: + +``` +$ convert picture.jpg -resize "750>" picture.jpg +``` + +which resizes `picture.jpg` by scaling it down to at most 750px width - +keeping the ratio between width and height, and leaving it untouched if it +is already smaller. The value 750 was chosen after a couple of attempts, +it seems a good compromise between quality and size. + +And now I just have to do this for all the pictures. Of course, running +the same command 10 times with a different argument is out of question. + +## find(1) + +*(No "man page reading club" this time, but don't +worry, the series will be back soon.)* + +A standard UNIX command, [`find`](https://man.openbsd.org/find) allows +you to scan a folder for files with certain properties (for example, +a certain name pattern) and perform actions on them (for example, +running a command). The OpenBSD and GNU versions of find have some +differences, check your local manual page. The commands I use +here have been tested on the GNU version, but should be standard. + +To look for file and simply print their name, we can use `-name`: + +``` +$ find src -name \*.jpg -or -name \*.png +src/me.png +src/favicon.png +src/speedcubing/cubing.png +src/blog/2023-01-28-windows-desktop/settings.png +src/blog/2023-01-28-windows-desktop/tiling.png +src/blog/2022-09-10-netbooks/darkstar.jpg +src/blog/2022-09-10-netbooks/final.jpg +src/blog/2022-09-10-netbooks/scramble.jpg +src/blog/2022-09-10-netbooks/hd.jpg +src/blog/2023-02-25-job-control/jobs-diagram.png +src/blog/2022-12-30-blog-ready/pc-planner.jpg +``` + +Now we can use `-exec` to run a command on each of these files, +using `{}` to refer to the file's name: + +``` +find src \( -name \*.jpg -or -name \*.png \) -exec convert {} -resize "750>" {} \; +``` + +We get a couple of warnings about grayscale images, but whatever. +This seems to have worked. diff --git a/src/blog/blog.md b/src/blog/blog.md index 8bd57ea..c74c703 100644 --- a/src/blog/blog.md +++ b/src/blog/blog.md @@ -5,6 +5,7 @@ ## 2023 +* 2023-03-06 [Resizing my website's pictures with ImageMagick and find(1)](2023-03-06-resize-pictures) * 2023-02-25 [Job control: one shell is all you need](2023-02-25-job-control) * 2023-01-28 [The year of the Windows desktop](2023-01-28-windows-desktop) * 2023-01-11 [Aaron Swartz](2023-01-11-aaron-swartz) diff --git a/src/blog/feed.xml b/src/blog/feed.xml index 88f547b..ab75982 100644 --- a/src/blog/feed.xml +++ b/src/blog/feed.xml @@ -8,6 +8,13 @@ Thoughts about software, computers and whatever I feel like sharing + +Resizing my website's pictures with ImageMagick and find(1) +https://sebastiano.tronto.net/blog/2023-03-06-resize-pictures +Resizing my website's pictures with ImageMagick and find(1) +2023-03-06 + + Job control: one shell is all you need https://sebastiano.tronto.net/blog/2023-02-25-job-control diff --git a/src/favicon.png b/src/favicon.png index 8a6b202..fca1e66 100644 Binary files a/src/favicon.png and b/src/favicon.png differ diff --git a/src/me.png b/src/me.png index 816c96f..0afd2ca 100644 Binary files a/src/me.png and b/src/me.png differ diff --git a/src/speedcubing/cubing.png b/src/speedcubing/cubing.png index 2c188d8..7ee8943 100644 Binary files a/src/speedcubing/cubing.png and b/src/speedcubing/cubing.png differ -- cgit v1.3