Python 小專案 - 一鍵壓縮圖片

Avatar of Pin You Lin.
Avatar of Pin You Lin.

Python 小專案 - 一鍵壓縮圖片

Digital Marketing Manager|Python Software Engineer|Web Developer
New Taipei, Banqiao District, New Taipei City, Taiwan

一鍵壓縮圖片:因為製作網站,經常需要上傳許多圖片,而圖片又偏偏是影響網站速度的大宗,所以都會將圖片都集齊,統一壓縮在上傳

import os

import tinify

import fnmatch


tinify.key = 'p8ZqCTGdVF0FK2B5wWcF7PFhm7bDRMJG'


'''

env

%pip install tinify


%source activate env


%python resize.py


'''


def tiny_image():

for fname in os.listdir('.'):

if fnmatch.fnmatch(fname, '*.jpeg') or fnmatch.fnmatch(fname, '*.png'):

print('compressing'+fname)

source = tinify.from_file(fname).to_file(fname)

print("changed", fname)


if __name__ == '__main__':

tiny_image()

一鍵壓縮圖片:因為製作網站,經常需要上傳許多圖片,而圖片又偏偏是影響網站速度的大宗,所以都會將圖片都集齊,統一壓縮在上傳
Avatar of the user.
Please login to comment.

Published: Jul 13th 2021
183
4
0

Tools

python
Python

resize
tiny image
line bot
linechatbot
imagemap
tinyjpg
application
app
python

Share