-
Notifications
You must be signed in to change notification settings - Fork 3
Simple Python Wrapper
nyfair edited this page Nov 15, 2021
·
1 revision
import ctypes
fi = ctypes.windll.freeimage
fi.FreeImage_LoadU.restype = ctypes.c_void_p
fi.FreeImage_SaveU.argtypes = [ctypes.c_int, ctypes.c_void_p, ctypes.c_wchar_p, ctypes.c_int]
def getfmt(name):
fmt = fi.FreeImage_GetFIFFromFilenameU(name)
if fmt > -1:
return fmt
else:
return fi.FreeImage_GetFileTypeU(name, 0)
def open(name, flag=0):
fmt = getfmt(name)
return fi.FreeImage_LoadU(fmt, name, flag)
def save(img, name, flag=0):
fmt = getfmt(name)
return fi.FreeImage_SaveU(fmt, img, name, flag)
x = open('text.png')
save(x, 'test.webp')