WEB开发网
开发学院手机开发iPhone 开发 将iPhone的png图片转换为可读png图片的Python源码... 阅读

将iPhone的png图片转换为可读png图片的Python源码

 2010-06-19 18:34:00 来源:WEB开发网   
核心提示:本段将iPhone的png图片转换为可读png图片的Python源码来自国外网站(代码注释里也能看到),原文地址 http://www.axelbrz.com.ar/?mod=iphone-png-images-normalizer#---# iPIN - iPhone PNG Images Normalizer v1

本段将iPhone的png图片转换为可读png图片的Python源码来自国外网站(代码注释里也能看到),原文地址 http://www.axelbrz.com.ar/?mod=iphone-png-images-normalizer

#---

# 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 x1a "

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]

1 2 3  下一页

Tags:iPhone png 图片

编辑录入:coldstar [复制链接] [打 印]
赞助商链接