Turn a bunch of colored JPG files in one folder into grayscale

Questions about applications and software
Forum rules
Before you post please read how to get help
User avatar
pepperminty
Level 5
Level 5
Posts: 869
Joined: Thu Jun 23, 2011 10:51 pm

Turn a bunch of colored JPG files in one folder into grayscale

Post by pepperminty » Mon Oct 14, 2019 5:43 am

I have a bunch of JPG files in a folder. They are full-color. To save space, I'd like to turn them into grayscale (16 shades max), but without losing quality. How can I do this easily?

User avatar
Moem
Level 19
Level 19
Posts: 9505
Joined: Tue Nov 17, 2015 9:14 am
Location: The Netherlands
Contact:

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by Moem » Mon Oct 14, 2019 6:02 am

XnView can do batch operations easily, including this one. It can be installed through the Software Manager.
Image

If your issue is solved, kindly indicate that by editing the first post in the topic, and adding [SOLVED] to the title. Thanks!

User avatar
absque fenestris
Level 6
Level 6
Posts: 1245
Joined: Sat Nov 12, 2016 8:42 pm
Location: Confoederatio Helvetica

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by absque fenestris » Mon Oct 14, 2019 6:34 am

pepperminty wrote:
Mon Oct 14, 2019 5:43 am
I have a bunch of JPG files in a folder. They are full-color. To save space, I'd like to turn them into grayscale (16 shades max), but without losing quality. How can I do this easily?
The conversion of JPG's is always afflicted with quality losses - and in addition into 16 grey tones... ... ...
Linux Mint 18.3 Sylvia (Mate) 32-bit - Acer D250 Netbook (Intel Atom N270, 2 GB RAM, 120 GB SSD)
Linux Mint 17.3 Rosa (Mate) 64-bit - MacBook Pro 15" (Intel Core2 Duo, 8 GB RAM, 240 GB SSD) - with some separation difficulties...

rene
Level 12
Level 12
Posts: 4251
Joined: Sun Mar 27, 2016 6:58 pm

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by rene » Mon Oct 14, 2019 7:12 am

absque fenestris wrote:
Mon Oct 14, 2019 6:34 am
The conversion of JPG's is always afflicted with quality losses - and in addition into 16 grey tones... ... ...
Other than the "quality loss" in the inherent sense of losing colour information itself, that's not in fact necessarily true. JPEG stores colour pixels in a YCbCr colour space where Y is a greyscale (luminance) value and Cb and Cr chrominance values, the three together in and of itself losslessly convertible to and from RGB. But this is to say that simply dumping Cb and Cr from the JPEG leaves one with greyscale, while having dumped nothing other than colour information.

Admittedly, I'm not sure whether or not the following in fact does that but I'd say chances are fair. sudo apt-get install imagemagick,

Code: Select all

convert colour.jpg -colorspace Gray grey.jpg
or

Code: Select all

for JPG in *.jpg; do convert "$JPG" -colorspace Gray "${JPG%.jpg}".grey.jpg; done
There's more detailed grey specifications than "Gray" available as well; see documentation; http://www.imagemagick.org/Usage/color_mods/#grayscale

Hoser Rob
Level 15
Level 15
Posts: 5588
Joined: Sat Dec 15, 2012 8:57 am

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by Hoser Rob » Mon Oct 14, 2019 8:07 am

absque fenestris wrote:
Mon Oct 14, 2019 6:34 am
pepperminty wrote:
Mon Oct 14, 2019 5:43 am
I have a bunch of JPG files in a folder. They are full-color. To save space, I'd like to turn them into grayscale (16 shades max), but without losing quality. How can I do this easily?
The conversion of JPG's is always afflicted with quality losses - and in addition into 16 grey tones... ... ...
+1, the idea that you can convert ANY lossy media format to another with no quality loss is a myth.

User avatar
thx-1138
Level 7
Level 7
Posts: 1923
Joined: Fri Mar 10, 2017 12:15 pm
Location: Athens, Greece

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by thx-1138 » Mon Oct 14, 2019 8:49 am

-1...

man jpegtran
NAME
jpegtran - lossless transformation of JPEG files
................
jpegtran works by rearranging the compressed data (DCT coefficients), without ever fully decoding the image.
Therefore, its transformations are lossless: there is no image degradation at all,
which would not be true if you used djpeg followed by cjpeg to accomplish the same conversion.
But by the same token, jpegtran cannot perform lossy operations such as changing the image quality.
However, while the image data is losslessly transformed, metadata can be removed. See the -copy option for specifics.
................
-grayscale
Force grayscale output.

This option discards the chrominance channels if the input image is YCbCr (ie, a standard color JPEG), resulting in a grayscale JPEG file.
The luminance channel is preserved exactly, so this is a better method of reducing to grayscale than decompression,
conversion, and recompression.

This switch is particularly handy for fixing a monochrome picture that was mistakenly encoded as a color JPEG.
(In such a case, the space savings from getting rid of the near-empty chroma channels won't be large;
but the decoding time for a grayscale JPEG is substantially less than that for a color JPEG.)
Now, if imagemagick does or does not the grayscale operation losslessly, i didn't checked myself either.
However, for the rest, if somehow still in...doubt, you can also read here (for a non-mathematician's reply),
or even better, just see rene's reply above (who is also a mathematician i believe)... :wink:

rene
Level 12
Level 12
Posts: 4251
Joined: Sun Mar 27, 2016 6:58 pm

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by rene » Mon Oct 14, 2019 9:31 am

Ah, great, had never heard of jpegtran. Was installed for me, but if not for OP, sudo apt-get install libjpeg-progs. Use:

Code: Select all

jpegtran -grayscale colour.jpg >grey.jpg
or

Code: Select all

for JPG in *.jpg; do jpegtran -grayscale "$JPG" >"${JPG%.jpg}".grey.jpg; done
Indeed that's lossless in the above mentioned sense, i.e., of dropping only chrominance. And, yes, I'm not sure either if ImageMagick's convert would. While as said lossless conversion to and from YCbCr from and to RGB is always possible, not all graphics file formats will supposedly make this as straightforward as JPEG and convert operates on any format; may therefore also for JPEG decode/recode.

A note by the way as to OP's specification of 16 grey values: theoretically simply quantizing the luminance down to 16 values would appear possible in that same "otherwise lossless" manner as with dumping the chrominance, but it seems jpegtran does not provide for it. Certainly it involves decoding all the lossless steps of JPEG compression after the actual lossy transform itself and recoding; if jpegtran doesn't provide for it I'd doubt anything would.

[EDIT] Thinking about that last statement a bit more, that's actually slightly nonsensical; there's no way to still call that "lossless" even with an "otherwise" qualifier. As in, yes, jpegtran is the best you're going to get.

User avatar
lsemmens
Level 9
Level 9
Posts: 2559
Joined: Wed Sep 10, 2014 9:07 pm
Location: Rural South Australia

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by lsemmens » Mon Oct 14, 2019 9:10 pm

The question I might ask is...to what end? Once you convert them to greyscale the colour is gone forever. If all you are doing is trying to save disk space, I'd recommend moving them to another drive, or get a bigger one.
Kernel: 4.15.0-46-generic x86_64 bits
Desktop: Cinnamon 3.8.9
Distro: Linux Mint 19 Tara

Laptop HP-ProBook-470-G2 8Gb RAM SSD
Server AMD Phenom 9650 - GEForce 9400GT 6Gb RAM
+ three other Mint machines
Out of my mind - please leave a message

User avatar
pepperminty
Level 5
Level 5
Posts: 869
Joined: Thu Jun 23, 2011 10:51 pm

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by pepperminty » Mon Oct 14, 2019 9:34 pm

The end is saving space on Kobo reader and speeding up performance on the ereader

User avatar
absque fenestris
Level 6
Level 6
Posts: 1245
Joined: Sat Nov 12, 2016 8:42 pm
Location: Confoederatio Helvetica

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by absque fenestris » Tue Oct 15, 2019 3:51 am

pepperminty wrote:
Mon Oct 14, 2019 9:34 pm
The end is saving space on Kobo reader and speeding up performance on the ereader
If you want to minimize the amount of image data on an ebook reader (Kobo) it would be good to know which image formats can be read at all.

Bitmap (pure black-and-white conversion) would also be a very economical option for this purpose - or GIF...
Linux Mint 18.3 Sylvia (Mate) 32-bit - Acer D250 Netbook (Intel Atom N270, 2 GB RAM, 120 GB SSD)
Linux Mint 17.3 Rosa (Mate) 64-bit - MacBook Pro 15" (Intel Core2 Duo, 8 GB RAM, 240 GB SSD) - with some separation difficulties...

User avatar
Moem
Level 19
Level 19
Posts: 9505
Joined: Tue Nov 17, 2015 9:14 am
Location: The Netherlands
Contact:

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by Moem » Tue Oct 15, 2019 4:15 am

pepperminty wrote:
Mon Oct 14, 2019 9:34 pm
The end is saving space on Kobo reader and speeding up performance on the ereader
See how you're doing that thing again? You've only now told us what the actual question is, namely:
How do I batch optimize a bunch of coloured JPG files for use on my Kobo reader?

Instead of asking us how to get to what you think the best answer is (grayscale), why not ask us the actual, broader question? The best answer may very well be outside of the scope of the question you asked us, so you are limiting the quality of the results you'll be getting. That's a waste of collective brainpower, and a waste of everyone's time... including yours.

I'm not saying this to pick on you, it's a mechanism I see all the time. This is just a very good example.
Someone wants to get from A to C, and thinks: I know how to get to B, and I probably need to get there first, so I'll ask how to get from B to C.
Great! But what if there actually is a direct route from A to C?
Image

If your issue is solved, kindly indicate that by editing the first post in the topic, and adding [SOLVED] to the title. Thanks!

rene
Level 12
Level 12
Posts: 4251
Joined: Sun Mar 27, 2016 6:58 pm

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by rene » Wed Oct 16, 2019 6:46 am

Moem wrote:
Tue Oct 15, 2019 4:15 am
Instead of asking us how to get to what you think the best answer is (grayscale), why not ask us the actual, broader question?
If it were me I'd answer that to be because of in that case immediately receiving "broad" replies as to how I should not be doing what I'm doing in the first place, and how 123 years ago back when respondent was growing up in Backwater, Kansas he or she had none of that ereader nonsense in the first place, and...

I.e., it pays to be specific; jpegtran was a good answer.

User avatar
Flemur
Level 17
Level 17
Posts: 7298
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by Flemur » Wed Oct 16, 2019 9:07 am

pepperminty wrote:
Mon Oct 14, 2019 9:34 pm
The end is saving space on Kobo reader and speeding up performance on the ereader
Because of the way JPEG compression deals with color, converting jpgs to grayscale won't save much space, only about 10%, not the 2/3rds you might have expected by converting from RGB triplet to one value.

Try using a lower quality compression, depending on the content of the image and the original encoding, sometimes you can make it 1/10th as large and it'll look the same (especially with lots of small detail like leaves) or almost the same.

Here's an example with a "typical" jpeg original:

Code: Select all

55540 Steve_cows_fire.jpg
06464 Steve_cows_fire_lowQ.jpg
50277 Steve_cows_fire_Gray.jpg
In the low quality image, almost 1/10the the size of the original, you can see blocks but everything is still completely identifiable. (I use irfanview's "Save for web" plugin which lets you preview the effects of compression before you save the file). The _Gray image was made with jpegtran.

Edit: png of screenshot; left image is original (55KB file) , right image is the low-quality (6KB file)
diff1.png
diff1.png (183.24 KiB) Viewed 385 times
Last edited by Flemur on Wed Oct 16, 2019 9:22 am, edited 1 time in total.
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?

User avatar
Moem
Level 19
Level 19
Posts: 9505
Joined: Tue Nov 17, 2015 9:14 am
Location: The Netherlands
Contact:

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by Moem » Wed Oct 16, 2019 9:20 am

rene wrote:
Wed Oct 16, 2019 6:46 am
If it were me I'd answer that to be because of in that case immediately receiving "broad" replies as to how I should not be doing what I'm doing in the first place, and how 123 years ago back when respondent was growing up in Backwater, Kansas he or she had none of that ereader nonsense in the first place, and...
Sure, answers that are outside the scope of the question will always be given... Sometimes that's a good thing, sometimes not so much. They're easy to ignore.
Answers that weren't given because the question was too narrow are a different matter: you'll never know what you missed.
Image

If your issue is solved, kindly indicate that by editing the first post in the topic, and adding [SOLVED] to the title. Thanks!

User avatar
phd21
Level 19
Level 19
Posts: 9402
Joined: Thu Jan 09, 2014 9:42 pm
Location: Florida

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by phd21 » Wed Oct 16, 2019 11:11 am

Hi pepperminty,

I just read your post and some of the good replies to it. Here are my thoughts on this as well.

+1 for using XnViewMP a great image browser with many image related functions and can easily convert an image or batch of images into other formats or into black and white or greyscale images.

+1 for Imagemagick which is usually pre-installed and is used by various desktop image related applications or from a console terminal command prompt.

There are a few commonly used image related processes to reduce space:

- Convert the image(s) to grayscale (greyscale) or black and white image(s). I think grayscale is better.

- Convert the image from one image format to another image format that uses compression like from Tiff to Jpeg or JPG which can reduce quality; usually the compression level is user adjustable.

- Reduce (shrink or scale down) the image(s) dimensions. If you have an option for "smooth scale" in an image application, then that works really well.

- Reduce the colors in the image(s)

If the original images were in color, then I would recommend leaving them in color and choose to reduce their dimensions (shrink or scale down) and or reduce the number of colors. Converting images into another format will change their filename extensions and then programs and or documents, or e-readers, etc... may not recognize them.

Almost all image editors can do this to an image and some like Gimp, XnViewMP (& XnConvert), Converseen (uses imagemagick), etc... can also do this in batches for all images in a folder.

Tip: I would recommend making a backup or archive file of the images in a folder, then experimenting with various applications and image reduction options to see which works best for you and for what you want to do. Once you have determined that, then you can use that same application and or technique over again.


Hope this helps ...
Phd21: Mint KDE 18.3 & 19, 64-bit Awesome OS, Ancient Dell OptiPlex 780 Core2Duo E8400 3GHz,4gb Ram,256gb SDD, Video: Intel 4 Graphics, DVD Lightscribe. Why I use KDE?:https://opensource.com/life/15/4/9-reasons-to-use-kde

User avatar
phd21
Level 19
Level 19
Posts: 9402
Joined: Thu Jan 09, 2014 9:42 pm
Location: Florida

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by phd21 » Wed Oct 16, 2019 1:06 pm

Hi pepperminty, and anyone else interested in this,

FYI: Just in case, for those who are not familiar with the excellent XnViewMP image browser, you can download their easy to install Linux deb file from their website and double-click it to install it. You can change the default XnViewMP view to your liking under View - Layouts (you can also resize the layout elements, or drag and drop them around the screen).

XnViewMP - scroll down to Linux downloads on right and pick 64-bit or 32-bit deb file.
https://www.xnview.com/en/xnviewmp/

This is an easy XnViewMP procedure to convert all (or some of) the images in a folder to greyscale, or reduce their colors used, or reduce their size, or all of these. I would try various options one at a time by outputting to a test folder to see the size affects each has on the original images.

I would highly recommend making a backup of the folder with the original images. You can bring up your file manager and right-click any folder and select compress to create an archive of the folder. I would recommend installing "p7zip-full" if you have not already done that. Then if you need to, you can just delete that folder, then right-click that archive file to restore it if necessary (extract) and overwrite.

1.) Bring up XnViewMP, click Tools in its toolbar, then Batch Convert, and a new pop-up "Batch Convert" window should appear with various tabs: Input, Actions, Output, Status, Settings.

2.) On the Input tab, click "Add Folder" at the bottom, and file browse to the folder with the images in it. Click the "choose" button, and you should see the images as thumbnails (note thumbnail options).

3.) click the "Actions" tab a very powerful feature of XnViewMP, click "clear all" button to remove any existing actions if there are any listed or keep them if they are what you want to use.

3.a) to convert images to grayscale, click "Add Action" button, select Image category and select "Change Color Depth", now that is listed under actions, click "Greyscale", (You can use the Preview box on the right side to see Before and After), go to step #4.

And OR
3.b) to reduce the colors used in the images, click "Add Action" button, select Image category and select "Change Color Depth", now that is listed under actions, click "Colors" and choose 256 or whatever, and if you want to try a different "Dithering" method select that, go to step #4.

And OR
3.c) to reduce the size of the images (shrink or scale), click "Add Action" button, select Image category and select "Resize", now that is listed under actions. You have various choices, check "keep ratio", you can enter in desired smaller width and height dimensions like 1024x768or whatever, or click the button to the right and select "Percent" and enter in a smaller percentage of the original images like 75% for each value (if you enter in width of 75% and hit tab with Keep Ratio checked, it should automatically enter in that value for height, if not enter it), go to step #4.

3.d) You can add various actions to this tab and they will be performed in order on all images selected. So, you could reduce the colors used and resize them at one time. Or, you could change them to greyscale and reduce their sizes the same way.

4.) click "Output" tab and and under Output options select Folder and select an output folder, click the ellipse (3 dots) to the right of folder for the converted images and you can create a new folder like "output-test-greyscale", or "output-test-color-reduction", or "output-test-resize", etc... Then, under filename options to keep the same filenames, click the list box and choose "{Filename}" option and backspace if needed so that only "{Filename}" shows in that filename box, leave case as "no change", under Format leave "As Original", you can leave the options below at their defaults or change them, then click the "Convert" button to convert them, and close the convert status window when it is finished.

5.) To see what happened, click or double-click the "output" folder or choose View Refresh if you used the same folder.


Hope this helps ...
.
XnViewMP Batch Convert<br />- Input Tab = source files and folders
XnViewMP Batch Convert
- Input Tab = source files and folders
.
XnViewMP Batch Convert<br />- Actions Tab to Greyscale, resize, reduce colors, convert to other formats, etc...
XnViewMP Batch Convert
- Actions Tab to Greyscale, resize, reduce colors, convert to other formats, etc...
.
XnViewMP Batch Convert<br />- Output Tab - where to put the changed images
XnViewMP Batch Convert
- Output Tab - where to put the changed images
Phd21: Mint KDE 18.3 & 19, 64-bit Awesome OS, Ancient Dell OptiPlex 780 Core2Duo E8400 3GHz,4gb Ram,256gb SDD, Video: Intel 4 Graphics, DVD Lightscribe. Why I use KDE?:https://opensource.com/life/15/4/9-reasons-to-use-kde

User avatar
absque fenestris
Level 6
Level 6
Posts: 1245
Joined: Sat Nov 12, 2016 8:42 pm
Location: Confoederatio Helvetica

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by absque fenestris » Wed Oct 16, 2019 5:10 pm

O.K. I am an old Mac OS, OSX / Photoshop user and my beloved applications are now hopelessly antiquated... what still works best on my old computers - but it can not be easily transferred to a current Linux, Windows or macOS System.

I have played around in a current GIMP 2.10 - and Oops! the converted JPG greyscale image is three times bigger than the original color image...
What I called "Bitmap" is old Photoshop - in GIMP 2.10 I didn't find this format.

https://en.wikipedia.org/wiki/Binary_image
Binary images are also called bi-level or two-level. This means that each pixel is stored as a single bit—i.e., a 0 or 1. The names black-and-white, B&W, monochrome or monochromatic are often used for this concept, but may also designate any images that have only one sample per pixel, such as grayscale images. In Photoshop parlance, a binary image is the same as an image in "Bitmap" mode
So I can create stupid small PDF's and bitmaps on my highly antiquated computers, but on new systems and new devices I don't find these possibilities anymore.
Linux Mint 18.3 Sylvia (Mate) 32-bit - Acer D250 Netbook (Intel Atom N270, 2 GB RAM, 120 GB SSD)
Linux Mint 17.3 Rosa (Mate) 64-bit - MacBook Pro 15" (Intel Core2 Duo, 8 GB RAM, 240 GB SSD) - with some separation difficulties...

User avatar
pepperminty
Level 5
Level 5
Posts: 869
Joined: Thu Jun 23, 2011 10:51 pm

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by pepperminty » Wed Oct 16, 2019 8:45 pm

rene wrote:
Mon Oct 14, 2019 9:31 am
Ah, great, had never heard of jpegtran. Was installed for me, but if not for OP, sudo apt-get install libjpeg-progs.

Code: Select all

sudo apt-get install libjpeg-progs
[sudo] password for pepper:        
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  libjpeg-turbo-progs xscreensaver-data-extra
The following NEW packages will be installed:
  libjpeg-progs
0 upgraded, 1 newly installed, 2 to remove and 0 not upgraded.
Need to get 71.7 kB of archives.
After this operation, 7,427 kB disk space will be freed.
I went ahead and chose "Y" for Yes, continue installation.

rene wrote:
Mon Oct 14, 2019 9:31 am
Use:

Code: Select all

jpegtran -grayscale colour.jpg >grey.jpg
or

Code: Select all

for JPG in *.jpg; do jpegtran -grayscale "$JPG" >"${JPG%.jpg}".grey.jpg; done
How can I convert all JPEGs in one folder into grayscale, while keeping the same filename for all files? For example, the colored version of aaa.jpg will still be named aaa.jpg, but now, it will be grayscale. Same with bbb.jpg and xyz.jpg.

User avatar
Moem
Level 19
Level 19
Posts: 9505
Joined: Tue Nov 17, 2015 9:14 am
Location: The Netherlands
Contact:

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by Moem » Thu Oct 17, 2019 2:37 am

absque fenestris wrote:
Wed Oct 16, 2019 5:10 pm
I can create stupid small PDF's and bitmaps on my highly antiquated computers, but on new systems and new devices I don't find these possibilities anymore.
Sounds like you need to start a topic of your own, then. We can probably help you if you do.
Image

If your issue is solved, kindly indicate that by editing the first post in the topic, and adding [SOLVED] to the title. Thanks!

rene
Level 12
Level 12
Posts: 4251
Joined: Sun Mar 27, 2016 6:58 pm

Re: Turn a bunch of colored JPG files in one folder into grayscale

Post by rene » Thu Oct 17, 2019 5:52 am

pepperminty wrote:
Wed Oct 16, 2019 8:45 pm
How can I convert all JPEGs in one folder into grayscale, while keeping the same filename for all files?
The straightforward way is generating the output into a temporary directory and then moving it over the original. As a single line:

Code: Select all

DIR=$(mktemp -d) && for JPG in *.jpg; do jpegtran -grayscale "$JPG" >$DIR/"$JPG" && mv $DIR/"$JPG" "$JPG"; done && rmdir $DIR
Yes, I'm not fond of those looping constructs in sh either; needing them is in the end a result of the POSIX shell behaviour of it rather than an individual program expanding wildcards such as *.jpg, and are what I would find to be a definite downside. What POSIX could've at least have done is introduce some kind of forall iterator syntax it seems. But oh well.

While testing that above line I do see that Flemur's right about the approximately 10% which might indeed be less than what you had expected / were aiming for; it's a lossless step of JPEG compression after the actual lossy transform, Huffman compression, which is responsible for that --- which is basically to say that JPEG compression is quite good to begin with.

You were originally specific about "without losing quality" and this jpegtran use is the best that's available while adhering to that. If however the savings aren't enough you'd go to my first suggestion of using convert while adding a -quality switch. If you are going to experiment, clearly do that on a copy of the original directory with JPEGs, because as per request this replaces the originals, but for example

Code: Select all

DIR=$(mktemp -d) && for JPG in *.jpg; do convert "$JPG" -quality 60 -colorspace Gray $DIR/"$JPG" && mv $DIR/"$JPG" "$JPG"; done && rmdir $DIR
See http://www.imagemagick.org/script/comma ... hp#quality. You'd need to be a graphics nerd to enjoy an option more involved than -quality but convert is a swiss army knife sort of application if you are. On a few tests I'd personally quickly find quality 60 to be good enough and on a few (natural) images here it gives me also approximately 60% reduction. YMMV.

[EDIT] Oh, I by the way see that you with convert don't need the entire tmpdir song and dance; works to do just

Code: Select all

for JPG in *.jpg; do convert "$JPG" -quality 60 -colorspace Gray "$JPG"; done
Generally that's dependent on the specific program; song-and-dance version is always safe (again, only experiment on copy of the originals).

Post Reply

Return to “Software & Applications”