- 浏览: 460475 次
- 性别:
- 来自: 广州
文章分类
- 全部博客 (538)
- C/C++ Primer (69)
- Objective-C Primer (102)
- Python Primer (19)
- JavaScript Primer (1)
- Java Primer (37)
- PHP Primer (17)
- 泛 Linux (37)
- Shell Script (21)
- APUE (21)
- UNP__1&2 (19)
- NetWork (7)
- Oracle周边 (38)
- Mysql里边 (6)
- Windows技 (9)
- 简单算法 & 数据结构 (14)
- 设计模式 (6)
- GTK历程 (12)
- 工具使用 (25)
- 杂事 (23)
- 一些概念 (17)
- Web方面 (10)
- myCodeTools (9)
- ^未 竟$ (13)
- 硬件通信 (2)
- Games (1)
最新评论
#---
# iPIN - iPhone PNG Images Normalizer v1.0
# Copyright (C) 2007
#
# Author:
# Axel E. Brzostowski
# http://www.axelbrz.com.ar/
# axelbrz@gmail.com
#
# References:
# http://iphone.fiveforty.net/wiki/index.php/PNG_Images
# http://www.libpng.org/pub/png/spec/1.2/PNG-Contents.html
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#---
from struct import *
from zlib import *
import stat
import sys
import os
def getNormalizedPNG(filename):
pngheader = "\x89PNG\r\n\x1a\n"
file = open(filename, "rb")
oldPNG = file.read()
file.close()
if oldPNG[:8] != pngheader:
return None
newPNG = oldPNG[:8]
chunkPos = len(newPNG)
# For each chunk in the PNG file
while chunkPos < len(oldPNG):
# Reading chunk
chunkLength = oldPNG[chunkPos:chunkPos+4]
chunkLength = unpack(">L", chunkLength)[0]
chunkType = oldPNG[chunkPos+4 : chunkPos+8]
chunkData = oldPNG[chunkPos+8:chunkPos+8+chunkLength]
chunkCRC = oldPNG[chunkPos+chunkLength+8:chunkPos+chunkLength+12]
chunkCRC = unpack(">L", chunkCRC)[0]
chunkPos += chunkLength + 12
# Parsing the header chunk
if chunkType == "IHDR":
width = unpack(">L", chunkData[0:4])[0]
height = unpack(">L", chunkData[4:8])[0]
# Parsing the image chunk
if chunkType == "IDAT":
try:
# Uncompressing the image chunk
bufSize = width * height * 4 + height
chunkData = decompress( chunkData, -8, bufSize)
except Exception, e:
# The PNG image is normalized
return None
# Swapping red & blue bytes for each pixel
newdata = ""
for y in xrange(height):
i = len(newdata)
newdata += chunkData[i]
for x in xrange(width):
i = len(newdata)
newdata += chunkData[i+2]
newdata += chunkData[i+1]
newdata += chunkData[i+0]
newdata += chunkData[i+3]
# Compressing the image chunk
chunkData = newdata
chunkData = compress( chunkData )
chunkLength = len( chunkData )
chunkCRC = crc32(chunkType)
chunkCRC = crc32(chunkData, chunkCRC)
chunkCRC = (chunkCRC + 0x100000000) % 0x100000000
# Removing CgBI chunk
if chunkType != "CgBI":
newPNG += pack(">L", chunkLength)
newPNG += chunkType
if chunkLength > 0:
newPNG += chunkData
newPNG += pack(">L", chunkCRC)
# Stopping the PNG file parsing
if chunkType == "IEND":
break
return newPNG
def updatePNG(filename):
data = getNormalizedPNG(filename)
if data != None:
file = open(filename, "wb")
file.write(data)
file.close()
return True
return data
def getFiles(base):
global _dirs
global _pngs
if base == ".":
_dirs = []
_pngs = []
if base in _dirs:
return
files = os.listdir(base)
for file in files:
filepath = os.path.join(base, file)
try:
st = os.lstat(filepath)
except os.error:
continue
if stat.S_ISDIR(st.st_mode):
if not filepath in _dirs:
getFiles(filepath)
_dirs.append( filepath )
elif file[-4:].lower() == ".png":
if not filepath in _pngs:
_pngs.append( filepath )
if base == ".":
return _dirs, _pngs
print "-----------------------------------"
print " iPhone PNG Images Normalizer v1.0"
print "-----------------------------------"
print " "
print "[+] Searching PNG files...",
dirs, pngs = getFiles(".")
print "ok"
if len(pngs) == 0:
print " "
print "[!] Alert: There are no PNG files found. Move this python file to the folder that contains the PNG files to normalize."
exit()
print " "
print " - %d PNG files were found at this folder (and subfolders)." % len(pngs)
print " "
while True:
normalize = raw_input("[?] Do you want to normalize all images (Y/N)? ").lower()
if len(normalize) > 0 and (normalize[0] == "y" or normalize[0] == "n"):
break
normalized = 0
if normalize[0] == "y":
for ipng in xrange(len(pngs)):
perc = (float(ipng) / len(pngs)) * 100.0
print "%.2f%% %s" % (perc, pngs[ipng])
if updatePNG(pngs[ipng]):
normalized += 1
print " "
print "[+] %d PNG files were normalized." % normalized
# iPIN - iPhone PNG Images Normalizer v1.0
# Copyright (C) 2007
#
# Author:
# Axel E. Brzostowski
# http://www.axelbrz.com.ar/
# axelbrz@gmail.com
#
# References:
# http://iphone.fiveforty.net/wiki/index.php/PNG_Images
# http://www.libpng.org/pub/png/spec/1.2/PNG-Contents.html
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#---
from struct import *
from zlib import *
import stat
import sys
import os
def getNormalizedPNG(filename):
pngheader = "\x89PNG\r\n\x1a\n"
file = open(filename, "rb")
oldPNG = file.read()
file.close()
if oldPNG[:8] != pngheader:
return None
newPNG = oldPNG[:8]
chunkPos = len(newPNG)
# For each chunk in the PNG file
while chunkPos < len(oldPNG):
# Reading chunk
chunkLength = oldPNG[chunkPos:chunkPos+4]
chunkLength = unpack(">L", chunkLength)[0]
chunkType = oldPNG[chunkPos+4 : chunkPos+8]
chunkData = oldPNG[chunkPos+8:chunkPos+8+chunkLength]
chunkCRC = oldPNG[chunkPos+chunkLength+8:chunkPos+chunkLength+12]
chunkCRC = unpack(">L", chunkCRC)[0]
chunkPos += chunkLength + 12
# Parsing the header chunk
if chunkType == "IHDR":
width = unpack(">L", chunkData[0:4])[0]
height = unpack(">L", chunkData[4:8])[0]
# Parsing the image chunk
if chunkType == "IDAT":
try:
# Uncompressing the image chunk
bufSize = width * height * 4 + height
chunkData = decompress( chunkData, -8, bufSize)
except Exception, e:
# The PNG image is normalized
return None
# Swapping red & blue bytes for each pixel
newdata = ""
for y in xrange(height):
i = len(newdata)
newdata += chunkData[i]
for x in xrange(width):
i = len(newdata)
newdata += chunkData[i+2]
newdata += chunkData[i+1]
newdata += chunkData[i+0]
newdata += chunkData[i+3]
# Compressing the image chunk
chunkData = newdata
chunkData = compress( chunkData )
chunkLength = len( chunkData )
chunkCRC = crc32(chunkType)
chunkCRC = crc32(chunkData, chunkCRC)
chunkCRC = (chunkCRC + 0x100000000) % 0x100000000
# Removing CgBI chunk
if chunkType != "CgBI":
newPNG += pack(">L", chunkLength)
newPNG += chunkType
if chunkLength > 0:
newPNG += chunkData
newPNG += pack(">L", chunkCRC)
# Stopping the PNG file parsing
if chunkType == "IEND":
break
return newPNG
def updatePNG(filename):
data = getNormalizedPNG(filename)
if data != None:
file = open(filename, "wb")
file.write(data)
file.close()
return True
return data
def getFiles(base):
global _dirs
global _pngs
if base == ".":
_dirs = []
_pngs = []
if base in _dirs:
return
files = os.listdir(base)
for file in files:
filepath = os.path.join(base, file)
try:
st = os.lstat(filepath)
except os.error:
continue
if stat.S_ISDIR(st.st_mode):
if not filepath in _dirs:
getFiles(filepath)
_dirs.append( filepath )
elif file[-4:].lower() == ".png":
if not filepath in _pngs:
_pngs.append( filepath )
if base == ".":
return _dirs, _pngs
print "-----------------------------------"
print " iPhone PNG Images Normalizer v1.0"
print "-----------------------------------"
print " "
print "[+] Searching PNG files...",
dirs, pngs = getFiles(".")
print "ok"
if len(pngs) == 0:
print " "
print "[!] Alert: There are no PNG files found. Move this python file to the folder that contains the PNG files to normalize."
exit()
print " "
print " - %d PNG files were found at this folder (and subfolders)." % len(pngs)
print " "
while True:
normalize = raw_input("[?] Do you want to normalize all images (Y/N)? ").lower()
if len(normalize) > 0 and (normalize[0] == "y" or normalize[0] == "n"):
break
normalized = 0
if normalize[0] == "y":
for ipng in xrange(len(pngs)):
perc = (float(ipng) / len(pngs)) * 100.0
print "%.2f%% %s" % (perc, pngs[ipng])
if updatePNG(pngs[ipng]):
normalized += 1
print " "
print "[+] %d PNG files were normalized." % normalized
发表评论
-
webpy_Cookbook
2013-05-06 22:31 617http://webpy.org/cookbook/index ... -
webpy_CGI 伏笔
2013-05-06 10:18 1141http://webpy.org/install.zh-cn ... -
python__re
2013-03-19 17:49 605xpath解析html,使用正则不好... http://ww ... -
Django
2013-03-03 20:04 995https://docs.djangoproject.com/ ... -
bpython IDE
2013-02-27 11:51 693http://bpython-interpreter.org/ ... -
install webpy
2012-07-20 20:58 607http://webpy.org/install.zh-cn ... -
python__zip
2012-06-14 10:26 674前几天用了下zip,要压缩个目录,下面那坨代码也是copy回 ... -
Python__列表
2011-02-12 14:23 632http://gmingzhe.blog.51cto.com/ ... -
Python__参数:传值or引用?
2011-02-12 14:20 622http://blog.csdn.net/winterTTr/ ... -
Python__递归遍历文件
2011-02-12 12:54 842http://zhangjunhd.blog.51cto.co ... -
Python__升级
2011-02-12 10:57 932http://www.activestate.com/ 出处 ... -
Python__模块
2011-02-11 15:48 778什么是模块:sys、time等模块,已经被封装起来,我们经常在 ... -
Python__函数
2011-02-11 15:18 721最基本函数 #!/usr/bin/python de ... -
Python__时间
2011-02-11 15:15 594当前时间 遍历时间 时间截 -
常用模块介绍
2010-07-22 15:48 646http://blog.csdn.net/Xiao_Qiang ... -
python编码相关
2010-07-22 09:54 999http://blog.csdn.net/lwl_ls/arc ... -
Python函数库列表
2010-07-21 21:05 1306copy:http://blog.ez2learn.com ... -
python__init
2010-05-27 10:22 613http://blog.sina.com.cn/s/artic ...
相关推荐
"各银行png图标"这个资源集合提供了各大银行的PNG图片以及对应的银行英文缩写,这对于设计师、开发者或者需要展示金融信息的项目来说非常有用。 PNG(Portable Network Graphics)是一种无损压缩的位图格式,支持...
本文将深入探讨"图标 PNG图标 APP开发专用图标"这一主题,包括其重要性、设计规范、不同规格以及如何在APP开发中有效使用。 首先,图标作为用户与应用交互的视觉元素,能够快速传达功能信息,提高用户体验。PNG格式...
UI素材 ICON素材 APP素材 PNG素材包 5G素材包 psd素材包
PNG格式的头像是数字图像处理领域中常用的一种文件格式,尤其在APP和网站设计中,因为其特性而广受欢迎。PNG(Portable Network Graphics)是一种无损压缩的位图格式,支持透明度设置,同时保留了图像的原始质量和...
商家APP.png
app支付交易流程图,java编程及示例,欢迎下载,谢谢
icon_app.png
沃尔特与iOS的法国红酒荣誉我我的风格环境看玩儿推儿童与你沃尔特与iOS的法国红酒荣誉我我的风格环境看玩儿推儿童与你沃尔特与iOS的法国红酒荣誉我我的风格环境看玩儿推儿童与你沃尔特与iOS的法国红酒荣誉我我的风格...
【标题】"appload-web.zip_234567png_aapp_appload_zip" 提供的信息主要涉及以下几个IT领域的知识点: 1. **文件压缩**:`zip` 是一种常见的文件压缩格式,用于将多个文件或文件夹打包成一个单一的压缩文件,以节省...
本教程将详细介绍如何提取iOS App和游戏中的PNG图片,并修复由Xcode优化导致的不兼容问题。我们将使用一个内置的脚本来完成这个过程,这个脚本可以解码优化过的PNG图像,使其恢复到可正常显示的状态。 首先,你需要...
"1000个常用精美软件PNG图标.rar" 提供了一套丰富的图标资源,这些图标适用于各种场景,特别是网站和ERP软件的开发。PNG图标因其高质量、透明度支持以及易于集成的特点,在数字产品设计中被广泛使用。 PNG...
村小爱app信息结构.png
本文将深入探讨一款备受软件和APP开发人员关注的图标资源库——“7000个APP小标图1632PNG格式.zip”。 首先,我们需要了解这款资源库的核心内容。正如标题所示,这是一款包含了7000个不同APP小图标的压缩文件,其中...
我们需要添加一个图像组件,并将其设置为timg.png。然后,我们添加一个方向传感器和一个绘图动画,将画布1和精灵1拖曳到界面中,并设置其高度和宽度。我们还需要设置精灵1的图片、X、Y和Z值。 第四步:编写代码。...
项目经验-APP思维导图.png
PNG(Portable Network Graphics)是一种无损压缩的位图格式,特别适合用于网页设计、图形编辑和数字艺术领域。PNG文件支持透明度,可以创建半透明效果,这在制作音画作品时非常有用,因为它允许背景和其他元素融合...
在这个场景下,我们有一个名为"Win32AppDemo"的压缩包文件,其中包含了一个基于Visual Studio 2010的测试项目,用于生成具有透明背景的PNG图像。下面将详细介绍这个过程涉及的知识点。 1. **PNG格式与Alpha通道**:...
app测试用例完整版
一起学——手机APP模块方案.png
BluetoothThis APP is a demo for bluetooth,which can transmit messages and files in the end.这是一个简单蓝牙APP,主要功能有扫描、配对;传输信息和文件。开发工具此APP开发的IDE为Android Studio 3.0APP截图