Reputation: 187
What can I use to read, process, convert, save, etc. image url with ".thumb" extension?
I rarely seen an image url with ".thumb" extension, so not sure which tool to use with it.
I tried using Requests to get the image from the URL and save as ".thumb" image format. But when I open the image, it is blank.
import requests
import shutil
image_url = 'https://slickdeals.net/attachment/5/4/8/0/7/1/200x200/9242327.thumb'
resp = requests.get(image_url, stream = True)
local_file = open('local_image.thumb', 'wb')
resp.raw.decode_content = True
shutil.copyfileobj(resp.raw, local_file)
del resp
Its the same if I save it as .jpg or .png. The image is blank.
Upvotes: 0
Views: 174
Reputation: 12672
You couldn't convert it directly because the bytes of the image is *.thumb
not *.jpg
or *.png
.
And there is no need to use stream=True
in your code.the image is not very large.
This code could download it directly:
import requests
image_url = 'https://slickdeals.net/attachment/5/4/8/0/7/1/200x200/9242327.thumb'
resp = requests.get(image_url)
with open('local_image.thumb', 'wb') as f:
f.write(resp.content)
And you also could use PIL
to convert it to jpg
,like:
import requests, io
from PIL import Image
image_url = 'https://slickdeals.net/attachment/5/4/8/0/7/1/200x200/9242327.thumb'
resp = requests.get(image_url)
image = Image.open(io.BytesIO(resp.content))
image.save("local_image.jpg")
Upvotes: 2