class coachpic(RequestHandler):
@gen.coroutine
def post(self):
picurl = self.request.files['picurl'][]
print("picurl:{}".format(picurl))
ret = yield self.editpic(picurl)
self.write(ret)
@gen.coroutine
def editpic(self,picfile):
filename = picfile["filename"]
current_path = os.getcwd()
print("cwd:{}".format(current_path))
originpath = current_path + "/templates/static/pics/coach/"
if os.path.exists(originpath) == False:
os.mkdir(originpath)
with open( originpath+ filename, "wb") as picwriter:
picwriter.write(picfile["body"])
saiwa = Image.open(originpath+ filename)
width = saiwa.size[]
height = saiwa.size[]
portion = / height
width = round(width * portion, )
height = round(height * portion, )
saiwa.thumbnail((width, height))
thpath = os.getcwd() + "/templates/static/thumbnail/coach/"
if os.path.exists(thpath) == False:
os.mkdir(thpath)
saiwa.save(thpath + "th_" + filename)
print("宽{},高{}".format(width, height))
originsrc = "/static/pics/coach/" + filename
subsrc = "/static/thumbnail/coach/" + "th_" + filename
raise Return({"origin": originsrc, "subsrc": subsrc})

一例tornado框架下处理上传图片并生成缩略图的例子的更多相关文章

  1. 一例tornado框架下利用python panda对数据进行crud操作

    get提交部分 <script> /* $("#postbtn").click(function () { $.ajax({ url:'/loaddata', data ...

  2. PHP.24-TP框架商城应用实例-后台1-添加商品功能、钩子函数、在线编辑器、过滤XSS、上传图片并生成缩略图

    添加商品功能 1.创建商品控制器[C] /www.test.com/shop/Admin/Controller/GoodsController.class.php <?php namespace ...

  3. MVC4 上传图片并生成缩略图

    Views @using (Html.BeginForm("Create","img",FormMethod.Post, new { enctype = &qu ...

  4. C#上传图片和生成缩略图以及图片预览

    因工作需要,上传图片要增加MIME类型验证和生成较小尺寸的图片用于浏览.根据网上代码加以修改做出如下效果图: 前台代码如下: <html xmlns="http://www.w3.or ...

  5. 【转】ASP.NET MVC框架下使用MVVM模式-KnockOutJS+JQ模板例子

    KnockOutJS学习系列----(一) 好几个月没去写博客了,最近也是因为项目紧张,不过这个不是借口,J. 很多时候可能是因为事情一多,然后没法静下来心来去写点东西,学点东西. 也很抱歉,突然看到 ...

  6. Js上传图片并生成缩略图

    Js上传图片并显示缩略图的流程为 Js选择文件->Jquery上传图片->服务器接收图片流->存储图片->返回结果到Js端->显示缩略图 本文上传图片所用的Js库是aja ...

  7. thinkphp上传图片,生成缩略图

    Image.php <?php /** * 实现图片上传,图片缩小, 增加水印 * 需要定义以下常量 * define('ERR_INVALID_IMAGE', 1); * define('ER ...

  8. C# webform上传图片并生成缩略图

    其实里面写的很乱,包括修改文件名什么的都没有仔细去写,主要是想记录下缩略图生成的几种方式 ,大家明白就好! void UpImgs() { if (FileUpload1.HasFile) { str ...

  9. C#上传图片同时生成缩略图,控制图片上传大小。

    #region 上传图片生成缩略图 /// <summary> /// 上传图片 /// </summary> /// <param name="sender& ...

随机推荐

  1. SaltStack安装部署

    SaltStack安装部署 安装: 一. master: 1. 配置yum源安装 # rpm --import https://repo.saltstack.com/yum/redhat/6/x86_ ...

  2. *【Python】【demo实验30】【练习实例】【使用Turtle实现实时时钟效果】

    目的: 使用Turtle实现实时时钟效果 源代码: # encoding=utf-8 # -*- coding: UTF-8 -*- import turtle from datetime impor ...

  3. Mf175-用户注册功能-埋点敏捷方案

    在不了解埋点系统的情况下,花了五六个小时 帮一位PM朋友做的方案.记录下来.以备后续参考 Mf178-用户注册功能-埋点敏捷方案 版本号 时间 撰写人 描述 V1.0 20190515-10:50:0 ...

  4. P1541 乌龟棋(动态规划)

    (点击此处查看原题) 题意 此处有n个位置,记为1~n,每个位置上都对应一个权值,乌龟从编号为1的位置出发,利用m张爬行卡片到达位置n,爬行卡牌有四种,分别可以让乌龟移动1,2,3,4步,并保证将m张 ...

  5. 代码优化:Java编码技巧之高效代码50例

    出处:  Java编码技巧之高效代码50例 1.常量&变量 1.1.直接赋值常量值,禁止声明新对象 直接赋值常量值,只是创建了一个对象引用,而这个对象引用指向常量值. 反例: Long i = ...

  6. JXOI 2018滚粗记

    --Update5.2 成绩出了,见后文 听说省选VAN写游记是传统,本蒟蒻也来发一篇吧. DAY 0 本来以为省选不在JKFZ举行的结果又是在JKFZ,本校作战感觉终究会是好一些吧,和jyh一起向教 ...

  7. 【Swift后台】环境安装

    macOS 在macOS上使用Vapor,需要Xcode 9.3或更高版本.Swift 4.1或更高版本.安装还需要Homebrew命令. 检查Swift版本: swift --version Vap ...

  8. 4.Linux用户与权限管理

    Linux 系统是一个多用于多任务的分时操作系统,任何一个要使用系统资源的用户,都必须首先向系统管理员申请一个账号,然后以这个账号的身份进入系统 新增用户: useradd  新用户名 设置密码:pa ...

  9. 第十章、collections

    目录 第十章.collections 一.OrderedDict方法 第十章.collections 一.OrderedDict方法 使用dict时,Key是无序的.在对dict做迭代时,我们无法确定 ...

  10. odoo标识符

    class Book(models.Model): _name = "library.book" _description = "Book" _order = ...