How to write several image tiles, from http request, into new image object in python?

大城市里の小女人 提交于 2020-05-17 06:06:23

问题


I need to request more than 100 image tiles from a server and save it in the new empty image object in a sequence and save the result on disk.

I can easily do the request and save a single image tile with the following code :

image_r = requests.get('https://myserver.com')
image = image_r.content
with open ('image.jpg', 'wb') as f
    f.write(image)
    f.close()

I have created an empty array to store all tiles from my request, but I am failing on looping over them and plotting to the new empty image object.

My tile size is 512x512, the empty image width and height are 9216x5120.

I need to plot is starting from x0, y0 upper left corner.

To create the new empty image object, I used PIL library :

empt_image = Image.new("RGB", (9216, 5120))

I new in developing and I have tried to do the following :

empt_image = Image.new("RGB", (9216, 5120))

counter = 0
images = []
image_r = requests.get('https://myserver.com')
images.append(r_imageTile.content)
counter += 1
for (i, image) in enumerate(images):
    empt_image.paste(image, (0, 9216, 512), (0, 5120, 512))

empt_image.save("image.jpg")

which gives me the following error :

AttributeError: 'tuple' object has no attribute 'load'`

This error may be because my tiles are in bytes, but I am not sure.

来源:https://stackoverflow.com/questions/61702854/how-to-write-several-image-tiles-from-http-request-into-new-image-object-in-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!