|
размер фото, определённый размер фото |
|
|
cirus |
3.9.2020, 5:16
|
Elder
Сообщений: 3.480
Регистрация: 18.8.2014 Группа: Пользователи Наличность: 26706
Пользователь №: 16.971
Возраст: 29
|
Узнать ширину и высоту изображения
Код --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
|
|
|
|
Fors1k |
3.9.2020, 12:46
|
Journeyman
Сообщений: 497
Регистрация: 19.12.2017 Группа: Пользователи Наличность: 2384
Пользователь №: 18.746
|
Цитата(portos @ 3.9.2020, 5:47) а такое возможно на нормальном uopilot ?
Нет, поэтому его больше и не используют. Посмотрите, здесь есть вся информация как начать писать скрипты. Обращайтесь, если появятся вопросы. Опишите полностью задачу пошагово, и тогда вам смогут помочь с написанием скрипта. Нужно просто скопировать все картинки из "D:\3" в "D:\2", которые больше 100х100px? Узнать ширину и высоту изображения:Код --lua require"luaposh";PScode('return',{[[#} # $image = [Drawing.Image]::FromFile("C:\myImg.jpg") log $image.size; $image.Dispose() # ]]}) Сообщение отредактировал Fors1k - 25.9.2020, 12:22
--------------------
Для связи
|
|
|
|
cirus |
3.9.2020, 14:57
|
Elder
Сообщений: 3.480
Регистрация: 18.8.2014 Группа: Пользователи Наличность: 26706
Пользователь №: 16.971
Возраст: 29
|
Цитата в папке D\3 находятся папки с фото,нужно оставить только файлы jpg которые больше 100х100 пикс код
Код --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;
bool DeleteFileA(const char *lpFileName); 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 = [[D:\3]] -- путь к папке
local resultarray, count = dir (path, "*.bmp;*.jpg", "norecursion") -- получить список всех файлов в формате bmp и jpg log ("Найдено файлов: " .. count) if count then -- если файлы найдены for i=1, #resultarray do local width, height = image_size( resultarray[i][1] ) log(resultarray[i][1].. '\tШирина: ' .. tostring(width) .. '\t'.. 'Высота: ' .. tostring(height)) -- размеры картинки if width < 100 and height < 100 then -- если ширина и высота меньше 100 ffi.C.DeleteFileA( resultarray[i][1] ) -- удалить файл end end end
|
|
|
|
cirus |
4.9.2020, 1:43
|
Elder
Сообщений: 3.480
Регистрация: 18.8.2014 Группа: Пользователи Наличность: 26706
Пользователь №: 16.971
Возраст: 29
|
Цитата работает если в папке только фото ,но если в папке D\3 папки с фото пишет - найдено файлов 0 Всего-то надо убрать "norecursion" в dir. код
Код --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;
bool DeleteFileA(const char *lpFileName); 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 = [[D:\3]] -- путь к папке
local resultarray, count = dir (path, "*.bmp;*.jpg") -- получить список всех файлов в формате bmp и jpg log ("Найдено файлов: " .. count) if count then -- если файлы найдены for i=1, #resultarray do local width, height = image_size( resultarray[i][1] ) log(resultarray[i][1].. '\tШирина: ' .. tostring(width) .. '\t'.. 'Высота: ' .. tostring(height)) -- размеры картинки if width < 100 and height < 100 then -- если ширина и высота меньше 100 ffi.C.DeleteFileA( resultarray[i][1] ) -- удалить файл end end end Цитата поэтому и не использую lua,много проблем с ним Это с языком пилота много проблем, поэтому и был переход на луа.
|
|
|
|
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0
|
|