python最新版安装图集_[python] plist图集拆分小图
#!python
importos,sysimportplistlibfrom PIL importImagedefgen_png_from_plist(plist_filename, png_filename):
file_path= plist_filename.replace(‘.plist‘, ‘‘)
big_image=Image.open(png_filename)
root=plistlib.readPlist(plist_filename)
frames= root[‘frames‘]
to_list= lambda x: x.replace(‘{‘,‘‘).replace(‘}‘,‘‘).split(‘,‘)
to_int= lambdax:int(x)for frame inframes:
framename= frame.replace(‘.png‘, ‘‘)
size=frames[frame].sourceColorRect
size=to_list(size)
size=map(to_int, size)
spriteSize=frames[frame].sourceSize
spriteSize=to_list(spriteSize)
spriteSize=map(to_int, spriteSize)
textureRect=frames[frame].frame
textureRect=to_list(textureRect)
textureRect=map(to_int, textureRect)
result_box=textureRect
result_image= Image.new(‘RGBA‘, spriteSize, 0)ifframes[frame].rotated:
result_box[0]=int(textureRect[0])
result_box[1] = int(textureRect[1])
result_box[2] = int(textureRect[0] + textureRect[3])
result_box[3] = int(textureRect[1] + textureRect[2])else:
result_box[0]=int(textureRect[0])
result_box[1] = int(textureRect[1])
result_box[2] = int(textureRect[0] + textureRect[2])
result_box[3] = int(textureRect[1] + textureRect[3])#print(result_box, frames[frame].rotated, frame)
rect_on_big=big_image.crop(result_box)ifframes[frame].rotated:
rect_on_big=rect_on_big.transpose(Image.ROTATE_90)
result_image.paste(rect_on_big)if notos.path.isdir(file_path):
os.mkdir(file_path)
outfile= (file_path+‘/‘ + framename+‘.png‘)print outfile, "generated"result_image.save(outfile)if __name__ == ‘__main__‘:
filename= sys.argv[1]
plist_filename= filename + ‘.plist‘png_filename= filename + ‘.png‘
if (os.path.exists(plist_filename) andos.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"
python最新版安装图集_[python] plist图集拆分小图相关推荐
- python mac os安装教程_教程:在 Mac OS X 上安装 TensorFlow
简评:手把手教你如何在 Mac OSX 系统安装 TensorFlow. 这个文档说明了如何在 Mac OS X 上安装 TensorFlow. 注意:从 1.2 版本开始,在 Mac OS X 上 ...
- python各种包安装顺序_史上最全的Python包管理工具:Anaconda教程
事实上Anaconda 和 Jupyter notebook已成为数据分析的标准环境. 简单来说,Anaconda是包管理器和环境管理器,Jupyter notebook 可以将数据分析的代码.图像和 ...
- python软件如何安装方法_【新手必看】Python软件下载及安装教程
原标题:[新手必看]Python软件下载及安装教程 Python下载:免费开源 官网地址:https://www.python.org/downloads/ 下载对应版本Python:python-3 ...
- python os模块安装方法_基于python中pygame模块的Linux下安装过程(详解)
一.使用pip安装Python包 大多数较新的Python版本都自带pip,因此首先可检查系统是否已经安装了pip.在Python3中,pip有时被称为pip3. 1.在Linux和OS X系统中检查 ...
- python嵩天课堂笔记_[Python机器学习]强化学习笔记(嵩天礼欣老师mooc第三周)
[Python机器学习]强化学习笔记(嵩天礼欣老师mooc第三周) [Python机器学习]强化学习笔记(嵩天礼欣老师mooc第三周) 目录 强化学习 定义 马尔科夫决策过程 基本元素 值函数 最优值 ...
- linux下载哪个python版本-Linux安装多个Python版本
服务器上的Python版本太老了,需要安装一个新的Python版本,才能跑我的代码.因为环境的需要,但是又不能卸载老的版本,所以安装一个新的,使用软链来进行升级. 使用系统自带的yum,apt-get ...
- 四全集学python选哪种电脑_“Python教程哪个版本最适合学习?“python教程全集
python教程,求一套比较好的python教程 好不好主要先看你自己,理解能力样,有没有接触过编程,有没础,这很重要: 看教程,能不能先给你建立起知识体系框架,许多教程一上来就直接给你灌输知识很让人 ...
- python如何设置字体大小_[Python Basic]如何设置 Python 的运行环境
一如既往地, 咱们不仅仅是学习 Python 的基础知识, 同时, 也按照2/8 规律学习关键知识的关键部分 - python 核心词汇 如何安装 Python 下载 Python 打开网址:http ...
- python 下载及安装-CentOS下python的下载及安装
针对" CentOS下python的下载及安装 "的问题,下面由IT产品经理-陆亦晓为您解答: Python这门编程语言在数据分析.数据发掘以及服务端开发等方面都有非常好的使用,我 ...
- python怎么下载安装mac_mac下PYTHON安装
Python3出来了(其实已经出来很久了,晕)! 但是还是有很多library还是使用Python2.7,所以要怎么在Mac里面同时装这两个版本,并且和系统所使用的Python区分开来呢?今天要写的是 ...
最新文章
- 基于DDD的.NET开发框架 - ABP初探
- 整个html和内部html,什么是HTML?
- 路径名导致的异常:javax.imageio.IIOException: Can‘t read input file!
- java系统系统异常处理,银行系统(Java)异常处理
- python 大量使用json 存储数据时,格式化输出的方式
- SES2 LED控制
- python http get 请求_Python:编写HTTP Server处理GET请求
- php商品评价代码,php商品对比功能代码分享
- samba和nfs的自动挂载
- Spring Security OAuth 个性化token 1
- 【正点原子MP157连载】第九章 STM32MP1时钟系统-摘自【正点原子】STM32MP1 M4裸机CubeIDE开发指南
- 海康SDK数据类型转java
- 数据库系统常用的数据模型
- 通过WIFI,访问一个网站
- php中notice怎么去掉,怎么关闭php的notice
- Spire.Office for Java 7.5.4
- Cookie的path和diamon
- C51实现时钟12MHz,使用定时器T1的方式1定时20mS ,做一个时分秒的电子钟。
- ChatGPT 侦探推理小说《神秘失踪》
- 宁波市第32届中小学生程序设计竞赛(初中组) 母鸡下蛋