Python uses Guetzli to batch compress images,
Google is now open-source again. This time, it opened up Guetzli, an image algorithm tool. Guetzli, a cookie in Swiss German, is a JPEG encoder for digital and web images, allows you to produce smaller JPEG files for a faster online experience and maintain compatibility with the current browser, image processing applications, and JPEG Standards. Google claims that Guetzli's creation of high-quality JPEG image files is 35% smaller than the current compression method.
Today, I played Guetzli, Google's open-source image compression tool, and found that the compression performance of a single image is good. I wrote a simple python script to compress images in batches.
Prerequisites
1. Install Guetzli and use the command line tool.
2. python Environment
Simple code
#-*-Coding: UTF-8-*-import osdir_name = "your image folder" def get_file_name (file_dir): for root, dirs, files in OS. walk (file_dir): print (root) # print (dirs) # print (files) return filesfiles = get_file_name (dir_name) print (files) OS. chdir (dir_name) for file in files: cmd = "guetzli -- quality 85 -- verbose" + file + "" + file OS. system (cmd)
Effect
Before Compression
After compression
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.