6. Images download - SheilaOM/TFG GitHub Wiki

Until now, I took the url of the image that they gave me and forced to download an image and name it with the .jpg format. This did not contemplate some problems:

  • Images format: Not all images are jpg. They can be png, jpeg ... (although if I named them as .jpg the Latex compiler supported it and taught me the image correctly).
  • .webp format: This format doesn't support that you name it as .jpg.
  • Url is not image: Some of the URLs given aren't of an image, but from a website where the image is.

The only problem that I contemplated is that the url was incorrect (Error 404).


Problems resolution

Images format

Before downloading the image, open the url (with urlopen) and get the type of content (image, text...). The content type (Content-Type) is formed by the type and format, both separated by '/', that is, the types can be image/jpg, image/png, text/html...

With this, I check if the url is an image (first part of the Content-Type is image). If it is, I download the image, and give it a name with its corresponding format (second part of Content-Type).

.webp format

Images with .webp format can not be opened, so I have to convert them to another format. For that, once I download the image I check if its format is .webp and, if it is, I convert it to .jpg. This process produces a copy of the .webp image in .jpg, so I have 2 copies of the same image, so once I have the .jpg format I delete the .webp.

Url is not image

If the content of the url is not an image, I can not get the image, so what I do is put an image that indicates that there is no image for that participant (as in the case of incorrect url). This image is downloaded to my local (I could download it too).


Link to commit of all of the images download


**Revision

I realized that when using /includegraphics to insert the images it isn't necessary to add the extension at the end of the file name (.jpg, .png ...), so I have deleted it when downloading the images. Link to commit of the images revision

When testing the code on a Windows computer, I realized again that the extension does not have to be added when indicating the name of the image in the .tex, but when downloading it, the extension must be indicated (I have modified in Section 9).