function exec(command)
local res = io.popen(command);
if res then
local ret = res:read("*a");
res:close();
return ret;
else
return -1;
end
end
function Split(szFullString, szSeparator)
local nFindStartIndex = 1
local nSplitIndex = 1
local nSplitArray = {}
while true do
local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
if not nFindLastIndex then
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
break
end
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)
nFindStartIndex = nFindLastIndex + string.len(szSeparator)
nSplitIndex = nSplitIndex + 1
end
return nSplitArray
end
function cleanPhoto()
exec("rm -rf /private/var/mobile/Media/PhotoData/*")
exec("rm -rf /private/var/mobile/Media/DCIM/*")
appKill("com.apple.mobileslideshow")
end
function main()
math.randomseed(tostring(os.time()):sub(5):reverse()); -- 随机种子
cleanPhoto() -- 清空相册
mSleep(1000)
local f = "/var/touchelf/" --图片目录
local list = exec(string.format( "find %s -name *.png", f))
local listTable = Split(list,'\n')
table.remove(listTable)
if #listTable > 0 then
local pic = listTable[math.random(1,#listTable)]
local resize = math.random(100,200) --随机缩放范围.自己修改
logDebug(pic)
imageResize(pic,resize,resize) --图片缩放
saveImageToAlbum(pic)
else
logDebug("文件夹内无图片")
end
end
function main()
socket = require('socket')
math.randomseed(socket.gettime() * 10000); -- 随机种子
cleanPhoto() -- 清空相册
mSleep(1000)
local f = "/var/touchelf/" --图片目录
local tmp = "/var/touchelf/tmp.png" --缓存图片(无需修改)
local list = exec(string.format( "find %s -name *.png", f)) --查找所有png图片
local listTable = Split(list,'\n')
table.remove(listTable)
if #listTable > 0 then
local pic = listTable[math.random(1,#listTable)]
local picInfo = exec(string.format( "file %s", pic))
logDebug(pic)
logDebug(picInfo)
local w,h = string.match(picInfo,", (%d+) x (%d+),")
if w and h then
logDebug(w..":"..h)
local resize = math.random(90,100) --随机缩放范围.自己修改
w = math.ceil(w * resize / 100)
h = math.ceil(h * resize / 100)
logDebug(w..":"..h)
exec(string.format( "cp %s %s", pic, tmp))
mSleep(1000)
imageResize(tmp,w,h) --图片缩放
saveImageToAlbum(tmp)
else
logDebug("图片格式错误")
end
else
logDebug("文件夹内无图片")
end
end