سؤال

In pgmagick, you initialize an image like this:

Image('my_image.png')

I will be operating on files stored remotely on S3 and would rather not temporarily store them on disk. Is there any way to open an image file from a URL instead? When I try to simply replace the file name with the URL, I get an error: Unable to open file.

I'd like to be able to use a URL. If anyone has any suggestions on that or how to extend pgmagick to achieve it, I'd be elated.

هل كانت مفيدة؟

المحلول

The easiest way (in my mind) is to use the awesome requests library. You can fetch each image from the server one at a time, then open it with Image():

from StringIO import StringIO
import requests
from pgmagick import Image, Blob

r = requests.get('https://server.com/path/to/image1.png', auth=('user', 'pass'))
img = Image(Blob(StringIO(r.content)))

And that's all there is to it. Authentication is of course not required, but may be necessary depending on your S3 setup. Have fun!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top