python通过PIL缩放互联网上的图片并保存的代码

下面的代码内容是关于python通过PIL缩放互联网上的图片并保存的代码,应该对小伙伴有较大用。‘’’ tk_image_view_url_io_resize.pydisplay an image from a URL using Tkinter, PIL and data_streamalso resize the web image to fit a certain size display widgetretaining its aspect ratioPil facilitates res
摘要由CSDN通过智能技术生成

下面的代码内容是关于python通过PIL缩放互联网上的图片并保存的代码,应该对小伙伴有较大用。

‘’’ tk_image_view_url_io_resize.py
display an image from a URL using Tkinter, PIL and data_stream
also resize the web image to fit a certain size display widget
retaining its aspect ratio
Pil facilitates resizing and allows file formats other then gif
tested with Python27 and Python33 by vegaseat 18mar2013
‘’’

import io
from PIL import Image, ImageTk
try:
# Python2
import Tkinter as tk
from urllib2 import urlopen
except ImportError:
# Python3
import tkinter as tk
from urllib.request import urlopen

def resize(w, h, w_box, h_box, pil_image):
‘’’
resize a pil_image object so it will fit into
a box of size w_box times h_box, but retain aspect ratio
‘’’
factor = min([f1, f2])
#print(f1, f2, factor) # test
# use best down-sizing filter
return pil_image.resize((width, hei

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值