图片压缩

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'])

  

压缩图片 Image的更多相关文章

  1. iOS学习-压缩图片(改变图片的宽高)

    压缩图片,图片的大小与我们期望的宽高不一致时,我们可以将其处理为我们想要的宽高. 传入想要修改的图片,以及新的尺寸 -(UIImage*)imageWithImage:(UIImage*)image ...

  2. Android压缩图片到100K以下并保持不失真的高效方法

    前言:目前一般手机的相机都能达到800万像素,像我的Galaxy Nexus才500万像素,拍摄的照片也有1.5M左右.这么大的照片上传到服务器,不仅浪费流量,同时还浪费时间. 在开发Android企 ...

  3. Android 高清加载巨图方案 拒绝压缩图片

    Android 高清加载巨图方案 拒绝压缩图片 转载请标明出处: http://blog.csdn.net/lmj623565791/article/details/49300989: 本文出自:[张 ...

  4. js压缩图片base64长度

    var myCanvas=$('.img-container > img').cropper('getCroppedCanvas'); (function (base64){ var image ...

  5. js上传压缩图片

    原文链接:http://blog.csdn.net/iefreer/article/details/53039848 手机用户拍的照片通常会有2M以上,这对服务器带宽产生较大压力. 因此在某些应用下( ...

  6. 等比例压缩图片到指定的KB大小

    基本原理: 取原来的图片,长宽乘以比例,重新生成一张图片,获取这张图片的大小,如果还是超过预期大小,继续在此基础上乘以压缩比例,生成图片,直到达到预期 /** * @获取远程图片的体积大小 单位byt ...

  7. 移动端使用localResizeIMG4压缩图片

    移动h5开发避免不了上传图片,一般我们使用html自带的控件input或者使用微信上传API.但微信上传API不是任何地方都可以使用的,使用html自带的控件input上传又免不了图片体积太大,上传不 ...

  8. java 上传图片 并压缩图片大小

    Thumbnailator 是一个优秀的图片处理的Google开源Java类库.处理效果远比Java API的好.从API提供现有的图像文件和图像对象的类中简化了处理过程,两三行代码就能够从现有图片生 ...

  9. 续Gulp使用入门三步压缩图片

    gulp 压缩图片 压缩 图片文件可降低文件大小,提高图片加载速度. 找到规律转换为 gulp 代码 规律 找到 images/ 目录下的所有文件,压缩它们,将压缩后的文件存放在 dist/image ...

  10. html5压缩图片并上传

    手机端图片有很大的,上传的时候很慢,这时候就要压缩一下了,有一个开源的js可以压缩图片的大小,开源地址如下:https://github.com/think2011/localResizeIMG3 代 ...

随机推荐

  1. Vue+Vue-router微信分享功能

    在使用vue和vue-router路由框架已经开发过好几个项目了,其中也遇到不少坑,有些坑各种搜也没有找到非常理想的答案. vue学习相对来说还是比较简单,官方文档说明非常清楚(https://cn. ...

  2. python使用requests发送application/json报文数据

    def client_post_jsondata_requests(request_url,requestJSONdata): #功能说明:发送json请求报文到指定的地址并获取请求响应报文 #输入参 ...

  3. SVD与SVD++

    参考自:http://blog.csdn.net/wjmishuai/article/details/71191945 http://www.cnblogs.com/Xnice/p/4522671.h ...

  4. 【Oracle】PL/SQL 显式游标、隐式游标、动态游标

    在PL/SQL块中执行SELECT.INSERT.DELETE和UPDATE语句时,Oracle会在内存中为其分配上下文区(Context Area),即缓冲区.游标是指向该区的一个指针,或是命名一个 ...

  5. window alias给cmd命令起别名

    场景: Linux的alias命令是个非常实用的工具,任何命令通过alias可以精简到很短,比如:alias l='ls -l' Windows也有alias类似的命令,就是:doskey,开启方法也 ...

  6. 线程锁Lock

    from threading import Thread, Lock import time def func(): global n n -= 1 n = 10 t_list = [] for i ...

  7. arch 相关软件及脚本

    安装 arch 脚本 sudo pacman -S arch-install-scripts 安装 ssh  并开启服务 sudo pacman -S open-ssh vim /etc/ssh/ss ...

  8. 16-1 ECMA5与ECMA6的函数定义

    ECMA5: function Drag(id){ this.ele = document.getElementById(id); var that = this; this.ele.onmoused ...

  9. vue 中的数据绑定

    vue当中有个v-model, 是怎么实现的呢?其实是利用了$event. <div id="app"> <!-- 输入什么,就输出什么 --> <i ...

  10. 一、HTML基础学习

    1.基本格式<html> <head><title></title></head> <body></body>< ...