Python uses Guetzli to bulk compress image instance code

Source: Internet
Author: User
This article mainly introduces Python to use Guetzli batch compressed pictures, detailed introduction of Google's Open source image compression Tool Guetzli, very practical value, the need for friends can refer to.

Google also open source, this time an open source of an image algorithm tool Guetzli. Guetzli, a "cookie" in Swiss German, is a JPEG encoder for digital images and web images, capable of achieving a faster online experience by generating smaller JPEG files, while maintaining compatibility with current browsers, image processing applications and JPEG standards. Google says Guetzli creates a high-quality JPEG image file that is 35% smaller than the current compression method.

Today played under the Google's Open source image compression Tool Guetzli, found that the single picture compression effect is still good, wrote a simple Python script, batch compressed pictures

Pre-conditions

1. Install Guetzli, you can use the command line tool

2.python Environment

A simple code

#-*-coding:utf-8-*-import osdir_name = "Picture folder of your choice" Def get_file_name (File_dir): For  root, dirs, files in Os.walk (fi Le_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--verbose" + file + "" + File  Os.system (c md

Effect

Before compressing

After compression

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.