Find photo in Drive

Asked

Viewed 33 times

0

I created a Google Forms form where I upload a photo, and I have another field where people describe the photo. The idea is to take this description and insert it into the photo description metadata. My problem is precisely being able to select the right photo to enter the information. The result of the google form generates a link where my photo was stored, inserir a descrição da imagem aqui However I could not find a way to upload the photo via this link the PIL, which are precisely the python libraries that I use to change the description of the photo.

The uploaded photo is saved to a folder in google drive with the original file name before uploading" - User name'".

Below I leave the part of the code that I have already implemented and serves as a basis for when I can select the right photo to enter the corresponding description:

for x in listadefotos: #faz o looping por todos os arquivos encontrados no diretorio
  foto = '/content/drive/My Drive/Pictures/Teste/' + x  #cria string de acesso a foto, aqui devo selecionar a foto correta, acessando pelo nome da foto, mas eu não terei essa informação
  
  im = ImagePil.open(foto) #PARTE DO CÒDIGO ONDE PRECISO PUXAR A FOTO DO DRIVE VIA LINK do FORMULARIO
  
  descricao = {270:'teste de descricao'} # cria descrição, tag 270 refere-se a ImageDescription DEVE-SE IMPLEMENTAR ESTA PARTE DO CÓDIGO APRA RECEBER OS DADOS DO FORMULÁRIO
  
  exif_dict = {"0th":descricao} # adicona a descrição no modelo exigido pela bblioteca
  exif_bytes = piexif.dump(exif_dict) #cria forma de inserção dos dados que serão inseridos
  novolocal = "/content/drive/My Drive/Pictures/Processados/" + x 
  im.save(novolocal, exif=exif_bytes) #cria novo arquivo alterado com as descrições passadas
  • The files stored in google drive do not have "conventional" formats. To download, you can use the files.export Google Drive API to download. https://developers.google.com/drive/api/v3/manage-downloads#python_1

  • Even downloading I could not relate to the information line of the form. If I use directly the way inside the drive I can open the photo, the problem is that it does not fit in my logic, because I will not know what is the name of the photo. I could even put a field in Forms for the user to fill in as the original name of the photo, but I can’t guarantee that it will insert correctly.

1 answer

1

From what I understand, you need the PIL to open an image that is on a link. For that, I believe the bilioteca requests associated with PIL would help in this.

from PIL import Image
import requests
from io import BytesIO

response = requests.get(url)
img = Image.open(BytesIO(response.content))

Example taken from from here.

I hope it helps.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.