我想用Base64替换所有图像文件,例如,我的源xml文件是这样的:
<?xml version="1.0" encoding="UTF-8" ?>
<!-- some other tags -->
<img src="http://example.com/img_194.jpg" />
<img src="http://example.com/photo5.jpg" />
<!-- some other tags -->
我希望我的目标xml文件变成这样:
<?xml version="1.0" encoding="UTF-8" ?>
<!-- some other tags -->
<img src="data:image/jpg;base64, iVBORw0ljNBAAO9TXLljNBAAO9TXL0Y4OHwKGgoAAAAN0ljNBAAO9TXL0Y4OHwKGgoAAAANY4OHwKGgoAAAANiV..." />
<img src="data:image/jpg;base64, w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABljNBAAO9TXL0Y4OHwKGgoAAAANJRU5ErkJggg=..." />
<!-- some other tags -->
任何解决方案?
答案 0 :(得分:1)
一种解决方案
perl -MDigest::MD5 -pi -e 's/src="([^"]+)"/"src=\"data:image\/jpg;base64, " . Digest::MD5::md5_base64($1)."\""/ge' file.xml