用shell加lua的方式制作一个项目png图片查重的小工具
shell查重耗时太严重,所以查重部分用lua处理比较快

--------shell脚本 开始-------------
–新建一个文件 auto_check_png_main.sh
以下是文件内容
#png图片查重小工具
#hank

#!/bin/bash
currentpath=$(dirname $0)
cd $currentpath

echo “-----开始查重-----”

rm -f “RES_FILE_ERROR”

#生成两个txt文件,分别用来保存查询到的plist里的png图名和外部的png图名
touch pngName1.txt
touch pngName2.txt
i=0
k=0
l=0
#递归查询res下文件,直到不是文件夹位置
function read_dir(){
for file in ls $1
do
if [ -d 1"/"1"/"1"/"file ]
then
read_dir 1"/"1"/"1"/"file
else
if [[ KaTeX parse error: Expected 'EOF', got '#' at position 31: …]] then #̲ .plist文件地址先缓存起…i]=1"/"1"/"1"/"file
((i++))
fi
if [[ $file = .png ]]
then
# 外部.png文件地址存到pngName2.txt里
((l++))
local name1=1"/"1"/"1"/"file
local name2=${name1##
…}
echo $name2 >> ./pngName2.txt
fi
fi
done
}

#循环遍历前面缓存的.plist地址表,查找每个文件里的png图
function dumpFileList(){
for plistName in ${fileList[@]}
do
getPngList $plistName
done
}

#输出单个.plist文件里所有含的行里包含.png的行
function getPngList(){
for line in cat $1
do
if [[ $line = “”* ]] && [[ line=∗.png∗]]thenpngList[line = *.png* ]] then pngList[line=∗.png∗]]thenpngList[k]=$line
((k++))
local name1=1localname2=1 local name2=1localname2={name1##…}
local name3=KaTeX parse error: Expected '}', got '#' at position 6: {line#̲*<key>} loca…{name3%
}
# 将每张图片名|图片所在.plist地址存到pngName1.txt里
echo name4"∣"name4"|"name4"∣"name2 >> ./pngName1.txt
fi
done
}

read_dir ./…/…/res
dumpFileList
#生成好pngName1.txt和pngName2.txt后调用lua脚本查重并通知钉钉
lua ./checkPngRepeat.lua
#删除两缓存文件
rm -f ./pngName1.txt
rm -f ./pngName2.txt

--------shell脚本 结束-------------

--------lua脚本 开始-------------
新建文件 checkPngRepeat.lua
以下是文件内容
–利用shell那边生成好的txt文件查重并输出
–hank
phoneNum = { --这里是所有svn上所有开发人员dingding号码
hank = “+86-178********”,
}

–字符串分割
function string.split(input, delimiter)
input = tostring(input)
delimiter = tostring(delimiter)
if (delimiter==’’) then return false end
local pos,arr = 0, {}
for st,sp in function() return string.find(input, delimiter, pos, true) end do
table.insert(arr, string.sub(input, pos, st - 1))
pos = sp + 1
end
table.insert(arr, string.sub(input, pos))
return arr
end
–通知钉钉 1.要输出的字符串 2.需要at的作者
function informDingDing(dingdingStr,authorData)
local json = require “cjson”

local _webhook = 'https://oapi.dingtalk.com/robot/send?access_token=39de0ace6b80a83cf1cb5fb376d68a392b733086b04d3d524b7fad3f7e72dccb'local atData = {}
for k,v in pairs(authorData) dotable.insert(atData,phoneNum[k])
end
local _content = {msgtype = 'text',text = {content = '--------【查重预警】--------\n\n'..dingdingStr,  --查重预警-- content = '[查重预警]\n'..dingdingStr,},at = {atMobiles = atData,isAtAll = false,},
}-- 加签相关 (把timestamp+"\n"+密钥当做签名字符串,使用HmacSHA256算法计算签名,然后进行Base64 encode,最后再把签名参数再进行urlEncode,得到最终的签名)
-- local mima = 'SECa4898f280dae75c3ab13977ac01df63495a771f1d6ab2bfe7011f665a0602501'
-- local time = os.time()
-- local sing = time .. '\n' .. mima
-- FIXME 太麻烦,不用这个方式了,选用关键字模式或者IP段做 local command = string.format([[curl '%s' -H 'Content-Type: application/json' -d '%s']], _webhook, json.encode(_content))print(command)
print('\n')os.execute(command)

end

–根据地址查最近一次提交的作者,path --文件地址
function getAuthor(path)
local t = io.popen(string.format(“svn log ./…/…%s”,path))
local a = t:read("*all")
if a == “” then
return “本地未提交”
else
local sqlData = string.split(a,"|")
local sqlData2 = string.split(sqlData[2]," ")
return sqlData2[2]
end
end

–读取shell生成好的txt文件
local file1 = io.open("./pngName1.txt",“r”) --格式xxx.png|/xx/xx/xx.plist
local file2 = io.open("./pngName2.txt",“r”) --格式/xx/xx/xx.png
local checkData = {}
local resultData = {}
local authorData = {}
local isRead1 = true
local isRead2 = true
while isRead1 do
local str = file1:read()
if not str then
isRead1 = false
else
local splData = string.split(str,"|")
–.plist文件内部查重
if checkData[splData[1]] then
local author1 = getAuthor(checkData[splData[1]])
local author2 = getAuthor(splData[2])
–将要输出到钉钉的文本存入resultData
table.insert(resultData,string.format("%s在plist文件里有重复,所在文件位置:%s和%s,作者:%s和%s",splData[1],checkData[splData[1]],splData[2],author1,author2))
–缓存作者名
if not authorData[author1] then
authorData[author1] = author1
end
if not authorData[author2] then
authorData[author2] = author2
end
else
checkData[splData[1]] = splData[2]
end
end
end
local checkData2 = {}
while isRead2 do
local str = file2:read() --读出来值图片地址
if not str then
isRead2 = false
else
local strData = string.split(str,"/")
local str2 = strData[#strData] --拆分完str2是图片名
–外部.png和plist里图片查重
if checkData[str2] then
local sqlData = string.split(checkData[str2],"/")
local sqlData2 = string.split(sqlData[#sqlData],".") --plist文件去掉后缀的名字
local sqlData3 = string.split(str2,".") --png文件去掉后缀的名字
–查出来外部图片和plist里图片重名且外部图片名字和plist名字相同则跳过,否则输出
if sqlData2[1] ~= sqlData3[1] then
local author1 = getAuthor(str)
local author2 = getAuthor(checkData[str2])
table.insert(resultData,string.format("%s为外部图片,和plist里图片重复,所在文件位置:%s和%s,作者:%s和%s",str2,str,checkData[str2],author1,author2))
if not authorData[author1] then
authorData[author1] = author1
end
if not authorData[author2] then
authorData[author2] = author2
end
end
end
–外部.png图片自身文件查重
if checkData2[str2] then
local author1 = getAuthor(checkData2[str2])
local author2 = getAuthor(str)
table.insert(resultData,string.format("%s在外部图片里有重复,所在文件位置:%s和%s,作者:%s和%s",str2,checkData2[str2],str,author1,author2))
if not authorData[author1] then
authorData[author1] = author1
end
if not authorData[author2] then
authorData[author2] = author2
end
else
checkData2[str2] = str
end
end
end
local dingdingStr = “”
if not next(resultData) then
print("-----没有重复图片,检测通过-----")
else
–将要输出到钉钉的文本data内容整合成一句
dingdingStr = table.concat(resultData,"\n")
–通知钉钉
informDingDing(dingdingStr,authorData)

os.execute("touch RES_FILE_ERROR"); os.exit()

end
print("-----查重结束-----")

--------lua脚本 结束-------------

下面是代码截图


png图片查重小工具相关推荐

  1. 本地查找重复/相似的图片、视频的图片查重工具

    查找各平台,比较了多种图片查重工具.理想的工具应该能查出完全相同或有一定相似度的图片,并兼具识别大量图片时的性能.研究了一下DuplicatePhotoFinder64是如何实现相似图片查找的. 首先 ...

  2. Android内存优化之图片查重

    本文将图片重复分为两种类型: 1.APP运行时加载了多个相同的图片对象,造成了内存浪费 2.APK包中存在多个相同的图片文件,影响了APK包大小 下面分别进行讨论: ----------------- ...

  3. max格式转obj小工具_PDF文件转JPG等图片格式的小工具

    不点蓝字,我们哪来故事? 今天小夭给大家介绍一个好用的PDF文件转JPG/PNG等图片格式的小工具,非常简单好用.它是一款免费的软件,一款体积小巧的PDF转换为图片文件的软件.PDF转JPG工具可以将 ...

  4. InkImageDataSetGenerator-开源一个可用于机器学习的书写轨迹图片生成的小工具

    这是一个简单易用的图片数据集生成小工具,基于OpenCV和UWP Ink API,它可以根据指定的手写轨迹生成一系列各个角度的图片.每张图片的尺寸和总体数量都是可以指定的,均存放在统一的生成目录中.h ...

  5. Excel数据查重小技巧

    Excel数据查重小技巧 方法一 1.选中要查重的一列(例如:A1) 2.点击:条件格式->突出显示单元格规则->重复值-确定 3.重复的数据就被标记出来了 方法二 1.选中要查询的数据列 ...

  6. Excel 查重小技巧,适用于office2003

    Excel 查重小技巧,适用于office2003 选中区域,格式,条件格式,公式  COUNTIF($A$1:$A$100,A1)>1 A代表列数,100代表行数,根据实际情况修改啦 很实用 ...

  7. 做自媒体进行文章查重的工具哪个好?操作方便快捷吗?

    做自媒体不仅要学会内容输出,还需要学会使用工具,使用工具能够让你的工作效率事半功倍,其实当你选择做了自媒体,那么就要在这块领域深耕,不断去学习,不断去进步,这样你才会发展的越来越好. 其实做自媒体,没 ...

  8. c语言.jpg图片转成数组_PDF文件转JPG等图片格式的小工具

    不点蓝字,我们哪来故事? 今天小夭给大家介绍一个好用的PDF文件转JPG/PNG等图片格式的小工具,非常简单好用.它是一款免费的软件,一款体积小巧的PDF转换为图片文件的软件.PDF转JPG工具可以将 ...

  9. 上传pdf文件转图片翻页小工具,遇到JSP form中type=file的文件上传及后台Part处理问题(后台取值为null)

    最近公司要求做一个上传pdf文件后将文件转换为翻页图片的小工具,我是这么做的 1.先找图片翻页的demo,微软有现有的产品turn.js感兴趣的可以自己看一下 ,有双页的有单页的,因为我司要求手机端使 ...

最新文章

  1. python打印汉字宝塔_利用宝塔+python+搭建falsk项目_详(一)
  2. 从函数调用过程中的堆栈变化理解缓冲区溢出
  3. linux全自动安装光盘,CentOS7全自动安装光盘制做详解
  4. sts(eclipse)安装svn插件
  5. 小师妹学JavaIO之:文件系统和WatchService
  6. QML笔记-对QML中信号与槽的基本认识
  7. python时间转换、给定一个以秒为单位的时间t_以秒为单位的历元时间和正常日期的差python...
  8. Intel SDM Chapter 10: APIC
  9. Err:error occurred at recursive SQL level 1
  10. IT程序员们平时都喜欢逛什么论坛呢?
  11. 6大维度重磅升级,容器云平台BeyondContainer发布1.8版本
  12. 在hisi上QT交叉编译过程(带webengine)
  13. 2022年2月份谷哥学术资源分下下载列表:19/20
  14. 毕业设计——房屋租赁管理系统
  15. 单片机实验一、单片机开发环境设置
  16. LaTex-使用texstudio插入参考文献
  17. 电箱吉他与原声吉他的区别在哪里?初学者应该选哪个呢?
  18. 内置方法及模块初识,set的hash算法面试题
  19. vue的form表单在提交成功后置空
  20. python并发编程-进程池线程池-协程-I/O模型-04

热门文章

  1. 中国移动MIFI--CM510,4G TD-LTE MIFI 上网终端开箱及初步体验@上海
  2. VDA6.5认证咨询,产品审核与其他审核方式及检验的区别
  3. PHP+MySQL实现学生信息管理系统登录功能(附带源码)
  4. Linux自动重启服务
  5. 奔图M9006DN复印机显示代码service error 191.10 engine error
  6. szshunjia储存不干胶标签的心得简述分享
  7. 清华物理系与计算机系哪个好,兰州大学现在还有物理系吗?
  8. oracle创建索引和删除索引
  9. 高频电容 低频电容
  10. 屏蔽掉Linux上运行Spark(Python版)时的多余信息(INFO)