-
-
Save kleisauke/7bf56f583ae32d0551991d841c481b36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from pyvips import ffi, vips_lib, Image, Error, _to_bytes | |
def has_loader(file): | |
name = vips_lib.vips_foreign_find_load(_to_bytes(file)) | |
if name == ffi.NULL: | |
return False | |
return True | |
# tmp file content = https://www.welt.de/favicon.ico | |
tmp_file = 'x' | |
loader = has_loader(tmp_file) | |
if loader: | |
print('.ico file has loader') | |
print('try to load it with new_from_file') | |
try: | |
image = Image.new_from_file(tmp_file) | |
print('Successfully load .ico with new_from_file. Loader: {}'.format(image.get('vips-loader'))) | |
except Error: | |
print('Failed to load .ico with new_from_file') | |
print('try to load it with thumbnail') | |
try: | |
thumb = Image.thumbnail(tmp_file, 200) | |
print('Successfully load .ico with thumbnail. Loader: {}'.format(thumb.get('vips-loader'))) | |
except Error: | |
print('Failed to load .ico with thumbnail') | |
else: | |
print('no loader for this image format') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment