zoukankan      html  css  js  c++  java
  • 压缩图片 Image

    图片压缩

    class resizeImg:
        """缩略图"""
        def __init__(self,**args):
            self.args_key = {'ori_img': '', 'dst_img': '', 'dst_h': '','dst_w': ''}
            self.arg = {}
            for key in self.args_key:
                if key in args:
                    self.arg[key] = args[key]
            self.im = Image.open(self.arg['ori_img'])
            self.ori_w, self.ori_h = self.im.size
            self.heightRatio = None
            self.widthRatio = None
            self.ratio = 1
    
        def hight(self):
            if self.ori_h and self.ori_h > self.arg['dst_h']:
                if self.arg['dst_h'] and self.ori_h > self.arg['dst_h']:
                    self.heightRatio = float(self.arg['dst_h']) / self.ori_h
                    ratio = self.heightRatio
                newWidth = int(self.ori_w * ratio)
                newHeight = int(self.ori_h * ratio)
            else:
                newWidth = self.ori_w
                newHeight = self.ori_h
            self.im.resize((newWidth, newHeight)).save(self.arg['dst_img'])
    
        def width(self):
            if self.ori_w and self.ori_w > self.arg['dst_w']:
                if self.arg['dst_w'] and self.ori_w > self.arg['dst_w']:
                    self.widthRatio = float(self.arg['dst_w']) / self.ori_w
                    ratio = self.widthRatio
                newWidth = int(self.ori_w * ratio)
                newHeight = int(self.ori_h * ratio)
            else:
                newWidth = self.ori_w
                newHeight = self.ori_h
            self.im.resize((newWidth, newHeight)).save(self.arg['dst_img'])
    

      

  • 相关阅读:
    使用babel插件集
    使用babel
    webpack基本配置
    vue-router参数传递
    路由(二) router-link的使用
    路由使用(一)
    获取DOM
    父组件传递值给子组件(一)
    定义全局组件
    Windows下更改MySQL数据库的存储位置
  • 原文地址:https://www.cnblogs.com/shizhengwen/p/7704884.html
Copyright © 2011-2022 走看看