Python uses Guetzli to batch compress images,

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.