--lua
local ffi = require('ffi')
local gdip = ffi.load('Gdiplus.dll')
local CP_ACP = 0
ffi.cdef[[
typedef unsigned int UINT;
typedef unsigned long DWORD;
typedef struct {UINT GdiplusVersion; int DebugEventCallback; bool SuppressBackgroundThread; bool SuppressExternalCodecs;} GdiplusStartupInput, *pGdiplusStartupInput;
int GdiplusStartup(int *token, pGdiplusStartupInput GdiplusStartupInput, int *output);
int GdiplusShutdown(int token);
int GdipDisposeImage(int image);
int GdipLoadImageFromFile(const wchar_t *filename, int *image);
int GdipGetImageWidth(int image, UINT *width);
int GdipGetImageHeight(int image, UINT *height);
int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, const char *lpMultiByteStr, int cbMultiByte, wchar_t *lpWideCharStr, int cchWideChar);
]]
function image_size(path)
local buf = ffi.new('wchar_t[?]', #path+1)
local StartupInput = ffi.new('GdiplusStartupInput', {1, 0, 0, 0})
local token, image, w, h = ffi.new('int[1]'), ffi.new('int[1]'), ffi.new('int[1]'), ffi.new('int[1]')
ffi.C.MultiByteToWideChar(CP_ACP, 0, path, #path, buf, ffi.sizeof(buf))
gdip.GdiplusStartup(token, StartupInput, nil)
gdip.GdipLoadImageFromFile(buf, image)
gdip.GdipGetImageWidth(image[0], w)
gdip.GdipGetImageHeight(image[0], h)
gdip.GdipDisposeImage(image[0])
gdip.GdiplusShutdown(token[0])
return w[0], h[0]
end
log "clear" log "mode compact"
local path = [[C:\image_062.jpg]] -- путь к картинке (возможные форматы: BMP, JPG, TIF, GIF и PNG)
local width, height = image_size( path )
log(width, height) -- размеры картинки
if width > 100 and height > 100 then
log('Размеры картинки больше 100')
else
log('Размеры картинки меньше 100')
end