Python uses Guetzli to batch compress image instance code

Source: Internet
Author: User
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!

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.