50 iOS路径照片随机到相册

发布于 2020-05-25 20:54:41

在线求助,清空相册,文件路径的文件夹里的图片,随机获取1张到相册。最好还能改变MD5只,如果不可以也没关系。

查看更多

关注者
0
被浏览
805
Evan
Evan 认证专家 2020-05-25
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
2 个回答
Evan
Evan 认证专家 2020-05-25
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

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览