根据 plist 还原 图片
1. python 环境自己配置(支持windows Mac )
2. 把所有的 plist 和 大图片放到一个目录下
3.如果添加了 系统环境变量 就直接双击运行脚本,如果没有设置,把脚本拽到DOS窗口下运行 就OK了
4. http://download.csdn.net/detail/wanggan768q/7411533 (支持 windows)
5.http://download.csdn.net/detail/wanggan768q/7432769 必须安装库
#!python
import os,sys
from xml.etree import ElementTree
from PIL import Image def endWith(s,*endstring):
array = map(s.endswith,endstring)
if True in array:
return True
else:
return False # Get the all files & directories in the specified directory (path).
def get_recursive_file_list(path):
current_files = os.listdir(path)
all_files = []
for file_name in current_files:
full_file_name = os.path.join(path, file_name)
if endWith(full_file_name,'.plist'):
full_file_name = full_file_name.replace('.plist','')
all_files.append(full_file_name) if os.path.isdir(full_file_name):
next_level_files = get_recursive_file_list(full_file_name)
all_files.extend(next_level_files) return all_files def tree_to_dict(tree):
d = {}
for index, item in enumerate(tree):
if item.tag == 'key':
if tree[index+1].tag == 'string':
d[item.text] = tree[index + 1].text
elif tree[index + 1].tag == 'true':
d[item.text] = True
elif tree[index + 1].tag == 'false':
d[item.text] = False
elif tree[index+1].tag == 'dict':
d[item.text] = tree_to_dict(tree[index+1])
return d def gen_png_from_plist(plist_filename, png_filename):
file_path = plist_filename.replace('.plist', '')
big_image = Image.open(png_filename)
root = ElementTree.fromstring(open(plist_filename, 'r').read())
plist_dict = tree_to_dict(root[0])
to_list = lambda x: x.replace('{','').replace('}','').split(',')
for k,v in plist_dict['frames'].items():
rectlist = to_list(v['frame'])
width = int( rectlist[3] if v['rotated'] else rectlist[2] )
height = int( rectlist[2] if v['rotated'] else rectlist[3] )
box=(
int(rectlist[0]),
int(rectlist[1]),
int(rectlist[0]) + width,
int(rectlist[1]) + height,
)
sizelist = [ int(x) for x in to_list(v['sourceSize'])]
rect_on_big = big_image.crop(box) if v['rotated']:
rect_on_big = rect_on_big.rotate(90) result_image = Image.new('RGBA', sizelist, (0,0,0,0))
if v['rotated']:
result_box=(
( sizelist[0] - height )/2,
( sizelist[1] - width )/2,
( sizelist[0] + height )/2,
( sizelist[1] + width )/2
)
else:
result_box=(
( sizelist[0] - width )/2,
( sizelist[1] - height )/2,
( sizelist[0] + width )/2,
( sizelist[1] + height )/2
)
result_image.paste(rect_on_big, result_box, mask=0) if not os.path.isdir(file_path):
os.mkdir(file_path)
outfile = (file_path+'/' + k).replace('gift_', '')
print outfile, "generated"
result_image.save(outfile) if __name__ == '__main__': currtenPath = os.getcwd()
allPlistArray = get_recursive_file_list(currtenPath) for plist in allPlistArray:
filename = plist
print filename
plist_filename = filename + '.plist'
png_filename = filename + '.png'
if (os.path.exists(plist_filename) and os.path.exists(png_filename)):
gen_png_from_plist( plist_filename, png_filename )
else:
print "make sure you have boith plist and png files in the same directory"
根据 plist 还原 图片的更多相关文章
- 将图片写入二进制文件,再从二进制文件还原图片(c++)
#include "string" #include "iostream" #include "fstream" using namespa ...
- 用 opencv和numpy进行图片和字符串互转,并保存至 json
用 opencv和numpy进行图片和字符串互转,并保存至 json 转至 https://zhuanlan.zhihu.com/p/27349847 受 用 base64 进行图片和字符串互转,并保 ...
- BMCP位图图片压缩算法
什么是位图?位图也称像素图像或点阵图像,是由多个点组成的,这些点被称为像素.位图可以模仿照片的真实效果,具有表现力强.细腻.层次多和细节多等优点. 图片的压缩格式:在Windows系统中,我们常见的b ...
- (4)Microsoft office Word 2013版本操作入门_插入图片及图片的排版
1.word中插入图片和文绕图 1.1插入图片 :点击[插入]-->[图片] 或者 [联机图片]从网上选择. 1.2文字环绕: [格式] --->点击[位置] .[自动换行] 进行图 ...
- iOS transform解决连续多次旋转缩放,实现图片旋转缩放效果
一.需求 实现imageView的缩放旋转效果,一般有两种方式: 1.底层加scrollview,利用scrollview的属性实现.(推荐这种,这是我比较后发现的,手势做缩放旋转会有点弊端) 2.利 ...
- 如何用Jquery做图片展示效果
一. 前言 到底用JQuery做出怎样的展示效果? 让我们先来看一下!网页加载时,如图所示: 二.本人思路 这个效果初学者看起来好像有点复杂,其实不太难,关键是理清思路,从后端的数据库中找出我们要展示 ...
- tf.nn.conv2d卷积函数之图片轮廓提取
一.tensorflow中二维卷积函数的参数含义:def conv2d(input, filter, strides, padding, use_cudnn_on_gpu=True, data_for ...
- 极验反爬虫防护分析之slide验证方式下图片的处理及滑动轨迹的生成思路
本文要分享的内容是去年为了抢鞋而分析 极验(GeeTest)反爬虫防护的笔记,由于篇幅较长(为了多混点CB)我会按照我的分析顺序,分成如下四个主题与大家分享: 极验反爬虫防护分析之交互流程分析 极验反 ...
- Python批量图片去水印,提高工作效率
平常工作中,有时为了采用网络的一些素材,但这些素材往往被打了水印,如果我们不懂PS就无法去掉水印,或者无法批量去掉水印.这些就很影响我们的工作效率. 今天我们就一起来,用Python + OpenC ...
随机推荐
- 从理论到实践,全方位认识DNS
从理论到实践,全方位认识DNS 2015-11-23 程序员之家 作者:selfboot 原文:http://segmentfault.com/a/1190000003956853 对于 DNS(Do ...
- 使用vue-cli3新建一个项目,并写好基本配置
1. 使用vue-cli3新建项目: https://cli.vuejs.org/zh/guide/creating-a-project.html 注意,我这里用gitbash不好选择选项,我就用了基 ...
- 迭代器 每迭代一次 指针往下面移动一次 除非JVM回收了内存 否则 他的指针不会回到原地
迭代器 每迭代一次 指针往下面移动一次 除非JVM回收了内存 否则 他的指针不会回到原地
- [十六]SpringBoot 之 读取环境变量和绑定属性对象
1.读取环境变量 凡是被spring管理的类,实现接口EnvironmentAware 重写方法 setEnvironment 可以在工程启动时,获取到系统环境变量和application配置文件中的 ...
- (转)java web自定义分页标签
转载至http://liuxi1024.iteye.com/blog/707784 效果如图: 1.JSP规范1.1版本后增加了自定义标签库.实现自定义标签的步骤 (1)开发自定义标签处理类. (2) ...
- 配置用户通过Telnet登录设备的身份认证(AAA本地认证)
背景信息 用户通过Telnet登录设备时,设备上必须配置验证方式,否则用户无法成功登录设备.设备支持不认证.密码认证和AAA认证三种用户界面的验证方式,其中AAA认证方式安全性最高. 采用AAA本地认 ...
- 洛谷P1602 Sramoc问题 题解报告【同余+bfs】
题目描述 话说员工们整理好了筷子之后,就准备将快餐送出了,但是一看订单,都傻眼了:订单上没有留电话号码,只写了一个sramoc(k,m)函数,这什么东西?什么意思?于是餐厅找来了资深顾问团的成员,YQ ...
- 网站统计IP PV UV实现原理
网站流量统计可以帮助我们分析网站的访问和广告来访等数据,里面包含很多数据的,比如访问试用的系统,浏览器,ip归属地,访问时间,搜索引擎来源,广告效果等.原来是一样的,这次先实现了PV,UV,IP三个重 ...
- 如何在 ASP.NET 应用程序中实现模拟用户身份(在ASP.NET中以管理员身份运行网站)
前言 在实际的项目开发中,我们可能会需要调用一些非托管程序,而有些非托管程序需要有更高的身份权限才能正确执行.本文介绍了如何让IIS承载的ASP.NET网站以特定的账户执行,比如Administrat ...
- 用一次FastDFS
FastDFS c编写的分布式文件系统,用于搭建文件服务器集群提供文件的上传.下载 特点 冗余备份 负载均衡 线性扩容 高性能.高可用 FastDFS架构 Tracker server 负载均衡和调度 ...