Gentoo Archives: gentoo-user

From: Michael <confabulate@××××××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] How do I compress jpeg files?
Date: Fri, 18 Sep 2020 15:02:26
Message-Id: 11602005.O9o76ZdvQC@lenovo.localdomain
In Reply to: Re: [gentoo-user] How do I compress jpeg files? by tastytea
1 On Friday, 18 September 2020 14:58:59 BST tastytea wrote:
2 > On 2020-09-18 13:32+0000 Alan Mackenzie <acm@×××.de> wrote:
3 > > Hello, Gentoo!
4 > >
5 > > I've a number of jpeg files, 17 to be precise, which are high
6 > > resolution and are around 3½ megabytes each. I would like to
7 > > compress them down to around 100 kb each.
8 > >
9 > > I'm sure this is possible, if tedious, in gimp, somehow, but I can't
10 > > for the life of me work out how (since it's years since I last did
11 > > this).
12 > >
13 > > What is the best way (minimal learning, scriptable if possible), to do
14 > > this?
15 >
16 > I'm not aware of a way that allows you to specify a file size, but you
17 > can use convert from media-gfx/imagemagick to re-compress and/or resize
18 > the files. For example:
19 >
20 > convert -quality 50 in.jpg out.jpg
21 > convert -resize 1000 in.jpg out.jpg
22 >
23 > The last command makes the image 1000px wide and sets the height
24 > automatically to the right value.
25 >
26 > Hope this helps,
27 > tastytea
28
29 I would also recommend convert, which can be scripted to run in a directory
30 and compress all jpeg files therein to a lower resolution. Something like
31 this ought to do the job:
32
33 #!/bin/bash
34 for i in *.jpg; do
35 name=${i%.jpg}
36 convert -compress JPEG -quality 95 ${i} ${name}_compressed.jpg
37 done
38
39 You'll need to adjust the -quality parameter to your liking.

Attachments

File name MIME type
signature.asc application/pgp-signature