Python/Django download Image from URL, modify, and save to ImageField

前端 未结 1 1694
执念已碎
执念已碎 2020-12-24 03:48

I\'ve been looking for a way to download an image from a URL, preform some image manipulations (resize) actions on it, and then save it to a django ImageField. Using the tw

相关标签:
1条回答
  • 2020-12-24 04:36

    In an attempt to kill 2 birds with 1 stone. Why not use a (c)StringIO object instead of a NamedTemporaryFile? You won't have to store it on disk anymore and I know for a fact that something like this works (I use similar code myself).

    from cStringIO import StringIO
    img_temp = StringIO()
    inImage.save(img_temp, 'PNG')
    img_temp.seek(0)
    
    file_object = File(img_temp, filename)
    
    0 讨论(0)
提交回复
热议问题