Resize an image retrieved from Google Drive using API
-
12-12-2019 - |
Question
I am using the following Python code to get a file from Google Drive:
theGoogleDriveFile = service.files().get(fileId=<googleDriveFileId>).execute()
How would I go about resizing this file if it is an image? I have tried the following:
resizedImage = images.resize(theGoogleDriveFile['downloadUrl'], 32, 32)
But I get the following error:
raise NotImageError()
NotImageError
Solution
This works:
theGoogleDriveFile = service.files().get(fileId=<googleDriveFileId>).execute()
result = urlfetch.fetch(theGoogleDriveFile['webContentLink'])
resizedImage = images.resize(result.content, 32, 32)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow