Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image format on imgur

I'm playing around in python trying to download some images from imgur. I've been using the urrlib and urllib.retrieve but you need to specify the extension when saving the file. This isn't a problem for most posts since the link has for example .jpg in it, but I'm not sure what to do when the extension isn't there. My question is if there is any way to determine the image format of the file before downloading it. The question is mostly imgur specific, but I wouldn't mind a solution for most image-hosting sites.

Thanks in advance

like image 905
user5977016 Avatar asked Jun 02 '26 11:06

user5977016


1 Answers

You can use imghdr.what(filename[, h]) in Python 2.7 and Python 3 to determine the image type.

Read here for more info, if you're using Python 2.7.

Read here for more info, if you're using Python 3.

like image 197
Andriy Stolyar Avatar answered Jun 04 '26 01:06

Andriy Stolyar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!