【问题标题】:Django: Download Image from URL, Resize it, append "small" to the end of the filenameDjango:从 URL 下载图像,调整大小,将“小”附加到文件名的末尾
【发布时间】:2013-09-09 17:02:36
【问题描述】:

我正在寻找一种从 URL 下载 640x640 图像、将图像大小调整为 180x180 并将单词 small 附加到调整大小的图像文件名末尾的方法。

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

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

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

【问题讨论】:

    标签: python django image


    【解决方案1】:

    为什么不试试 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")
    

    然后,要调整它的大小,您可以使用 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")
    

    参考资料:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-26
      • 1970-01-01
      • 1970-01-01
      • 2020-10-22
      • 1970-01-01
      • 1970-01-01
      • 2021-02-19
      相关资源
      最近更新 更多