This article mainly introduces python's use of Guetzli to batch compress images. it describes in detail the open-source image compression tool Guetzli of Google, which is of great practical value. if you need it, you can refer to it. This article mainly introduces python's use of Guetzli to batch compress images. it describes in detail the open-source image compression tool Guetzli of Google, which is of great practical value. if you need it, you can refer to it.
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
The above is the detailed content of python's code for compressing image instances in batches using Guetzli. For more information, see other related articles in the first PHP community!