Reputation: 2400
I want to optimize the whole test folder with jpg images from a command line. I found this but it doesn't work:
cd /home/site/html/update/test/
find . -exec jpegtran -optimize "{}" "{}.opti.jpg" "{}" \;
I want to overwrite the existing images.
Suggestions?
Answer:
find /img/path -name "*.jpg" -type f -exec jpegtran -copy none -optimize -outfile {} {} \;
Upvotes: 8
Views: 5410
Reputation: 207758
Get them all done more succinctly and in parallel using GNU Parallel as follows:
parallel jpegtran -copy none -optimize -outfile {} {} ::: *.jpg
Use parallel --eta ...
or parallel --bar ...
for estimated time of arrival or progress bar.
Upvotes: 0
Reputation: 1047
Though it is solved here pretty earlier but talking about Python approach:
import subprocess
for image_name in arr:
subprocess.call(["jpegtran", "-your", "-instructions"])
Let's say your instruction is something like:
jpegtran -optimize -progressive -scans script_new.txt -outfile progressive.jpg original.jpg
So your instruction will be like:
subprocess.call(["jpegtran", "-optimize", "-progressive", "-scans", f"{scan_name}.txt", "-outfile", name_progressive, name_original])
For your convenience, name_progressive, name_original and scan_name are variables and concept f-string is used.
Upvotes: 0
Reputation: 2400
Answer:
find /img/path -name "*.jpg" -type f -exec jpegtran -copy none -optimize -outfile {} {} \;
Upvotes: 2