Django:从URL下载图片,调整大小,追加“小”到文件名的末尾 [英] Django: Download Image from URL, Resize it, append "small" to the end of the filename

查看:514
本文介绍了Django:从URL下载图片,调整大小,追加“小”到文件名的末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种从URL下载640x640图像的方法,将图像大小调整为180x180,并将该字小写到调整大小的图像文件名的末尾。



例如,图片位于此链接
http://0height.com/wp-content/uploads/2013/07/18-japanese-food-instagram-1.jpg



一旦调整大小,我想将这个世界小到附加文件名的末尾,如:
18-japanese-food-instagram-1small.jpeg



如何做到这一点?下载的图像还将保存到内存中或将其保存到实际的驱动器?如果它保存到驱动器,是否可以删除原始图像并保留调整大小的版本?

解决方案

你尝试urllib?

  import urllib 
urllib.urlretrieve(http://0height.com/wp-内容/上传/ 2013/07/18-japanese-food-instagram-1.jpg,18-japanese-food-instagram-1.jpg)

然后,要调整大小,您可以使用PIL或另一个库

  import image 
im1 = Image.open(18-japanese-food-instagram-1.jpg)
im_small = im1.resize((width,height),Image.ANTIALIAS)
im_small.save(18-japanese-food-instagram-1_small.jpg)

参考文献: / p>

http://www.daniweb.com/software-development/python/code/216637/resize-an-image-python
通过urllib和python下载图片


I'm looking for a way to download an 640x640 image from a URL, resize the image to 180x180 and append the word small to the end of the resized image filename.

For example, the image is located at this link http://0height.com/wp-content/uploads/2013/07/18-japanese-food-instagram-1.jpg

Once resized, I would like to append the world small to the end of the filename like so: 18-japanese-food-instagram-1small.jpeg

How can this be done? Also will the downloaded image be saved to memory or will it save to the actual drive? If it does save to the drive, is it possible to delete the original image and keep the resized version?

解决方案

Why don't you try urllib?

import urllib
urllib.urlretrieve("http://0height.com/wp-content/uploads/2013/07/18-japanese-food-instagram-1.jpg", "18-japanese-food-instagram-1.jpg")

Then, to resize this you can use PIL or another library

import Image
im1 = Image.open("18-japanese-food-instagram-1.jpg")    
im_small = im1.resize((width, height), Image.ANTIALIAS)
im_small.save("18-japanese-food-instagram-1_small.jpg")

References:

http://www.daniweb.com/software-development/python/code/216637/resize-an-image-python Downloading a picture via urllib and python

这篇关于Django:从URL下载图片,调整大小,追加“小”到文件名的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆