根据 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 ...
随机推荐
- PHP 多文件打包下载 zip
<?php $zipname = './photo.zip'; //服务器根目录下有文件夹public,其中包含三个文件img1.jpg, img2.jpg, img3.jpg,将这三个文件打包 ...
- HTML5资源站
前端里:http://www.yyyweb.com/ http://www.cnblogs.com/html5tricks/p/3925844.html
- webgl学习笔记四-动画
写在前面 建议先阅读下前面我的三篇文章. webgl学习笔记一-绘图单点 webgl学习笔记二-绘图多点 webgl学习笔记三-平移旋转缩放 下面我们将讲解下如何让一个正方形动起来~不断擦除和重绘 ...
- postgis_LayerTransform
[转] postgis_LayerTransform 一个在postgis中结合中国国情,批量对数据进行加偏到百度坐标,高德谷歌的火星坐标,或者逆向纠偏 安装: 在postgresql-postgis ...
- postman 断言学习
请求 url :https://www.v2ex.com/api/nodes/show.json?name=python get请求 postman发起请求并做断言 断言: tests["B ...
- js复选框插件
<div class="selectList selectQgClass" id="selectQgClass"> <div class=&q ...
- BIOS和CMOS的区别
原文链接:https://www.cnblogs.com/boltkiller/articles/5732424.html 在日常操作和维护计算机的过程中,常常可以听到有关BIOS设置和CMOS设置的 ...
- 修改apache的注册表值提高系统权限
In Windows environments when a service is registered with the system a new key is created in the reg ...
- HDU1863畅通工程---并查集+最小生成树
#include<cstdio> #include<algorithm> #define MAX 105 struct edge { int from,to; long lon ...
- 使用adb命令查看apk版本
adb devices (显示连接的设备) adb root (获取手机root权限) adb remount (重新挂载系统分区,使系统分区重新可写) adb shell (进入目标设备的L ...