L
L
Lici2014-07-12 17:05:26
bash
Lici, 2014-07-12 17:05:26

How to reduce thousands of pictures in all subfolders?

There is a site on WordPress and there are a bunch of pictures that I would like to shrink in quality up to 60-70%. Yes, it can be size.
They lie in a subfolder for months and years. I have a Linux PC and a MacBook Pro at my disposal, that is, all the power of the consoles is at my service.
How and what is the best way to "sort through" all the folders and compress everything in them? I can only pinch everything in one folder.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
sim3x, 2014-07-12
@Lici


We need mogrify packages ,
everything will happen in place - files are replaced
starting from the current folder and further in depth
if there is no height (width), then we change proportionally the
maximum number of passes over the image, very effective for running cases, very, very long
a couple of minutes for a file 1500x1500
just a long time
# the code is provided as is
# why optipng is drop dead
# for other types of images we change find and look for what software will optimize them
. You can also convert images to png-jpg, but often this somehow needs to be synchronized with the database, and there is no easy way

V
Viktor Taran, 2017-11-08
@shambler81

yum install jpegoptim
or
, well, the process itself

find /home/bitrix/ext_www/shop.wildorchid.ru/-type f -regex ".*\(jpg\|jpeg\|JPG\|Jpeg\)" -exec jpegoptim -t --max=85 {} \;

G
GavriKos, 2014-07-12
@GavriKos

Python+ImageMagic.

V
Vladlen Grachev, 2014-07-12
@gwer

How and what is the best way to "sort through" all the folders and compress everything in them? I can only pinch everything in one folder.

Well, if so, then there shouldn't be a problem. Just traverse the directory tree recursively.
Let's say you are writing a compressFolder(folder) function that will compress the contents of the directory passed as a parameter. You iterate over all the contents in it, according to the following principle: if this is an image, you compress it (you know how), and if it is a folder (for example, the path to it is written in folder_i), then call compressFolder (folder_i). Thus, a recursive traversal of the directory tree is performed.
PS: yes, the @sim3x version is much more interesting.

S
Semyon Voronov, 2014-07-22
@Gineaser

Maybe don't compress anything and use Nginx Image Filter Module ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question