`

app PNG

 
阅读更多
#---
# 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
分享到:
评论

相关推荐

    各银行png图标

    "各银行png图标"这个资源集合提供了各大银行的PNG图片以及对应的银行英文缩写,这对于设计师、开发者或者需要展示金融信息的项目来说非常有用。 PNG(Portable Network Graphics)是一种无损压缩的位图格式,支持...

    图标 PNG图标 APP开发专用图标

    本文将深入探讨"图标 PNG图标 APP开发专用图标"这一主题,包括其重要性、设计规范、不同规格以及如何在APP开发中有效使用。 首先,图标作为用户与应用交互的视觉元素,能够快速传达功能信息,提高用户体验。PNG格式...

    UI素材 ICON素材 APP素材 PNG素材包 电商素材包 psd素材包 大小5G

    UI素材 ICON素材 APP素材 PNG素材包 5G素材包 psd素材包

    APP头像,PNG格式头像67张

    PNG格式的头像是数字图像处理领域中常用的一种文件格式,尤其在APP和网站设计中,因为其特性而广受欢迎。PNG(Portable Network Graphics)是一种无损压缩的位图格式,支持透明度设置,同时保留了图像的原始质量和...

    商家APP.png

    商家APP.png

    App支付.png

    app支付交易流程图,java编程及示例,欢迎下载,谢谢

    icon_app.png

    icon_app.png

    app_big_hot.png

    沃尔特与iOS的法国红酒荣誉我我的风格环境看玩儿推儿童与你沃尔特与iOS的法国红酒荣誉我我的风格环境看玩儿推儿童与你沃尔特与iOS的法国红酒荣誉我我的风格环境看玩儿推儿童与你沃尔特与iOS的法国红酒荣誉我我的风格...

    appload-web.zip_234567png_aapp_appload_zip

    【标题】"appload-web.zip_234567png_aapp_appload_zip" 提供的信息主要涉及以下几个IT领域的知识点: 1. **文件压缩**:`zip` 是一种常见的文件压缩格式,用于将多个文件或文件夹打包成一个单一的压缩文件,以节省...

    提取IOS App及游戏中的PNG图片

    本教程将详细介绍如何提取iOS App和游戏中的PNG图片,并修复由Xcode优化导致的不兼容问题。我们将使用一个内置的脚本来完成这个过程,这个脚本可以解码优化过的PNG图像,使其恢复到可正常显示的状态。 首先,你需要...

    7000个APP小标图1632PNG格式.zip

    标题中的"7000个APP小标图1632PNG格式.zip"指的是一个包含7000个不同APP小图标的压缩文件,这些图标是PNG图像格式,且提供了两种尺寸,即16x16像素和32x32像素。在软件开发和APP开发领域,图标是用户界面设计的重要...

    1000个常用精美软件PNG图标.rar

    "1000个常用精美软件PNG图标.rar" 提供了一套丰富的图标资源,这些图标适用于各种场景,特别是网站和ERP软件的开发。PNG图标因其高质量、透明度支持以及易于集成的特点,在数字产品设计中被广泛使用。 PNG...

    村小爱app信息结构.png

    村小爱app信息结构.png

    App Inventor创意编程:指南针App制作.pdf

    我们需要添加一个图像组件,并将其设置为timg.png。然后,我们添加一个方向传感器和一个绘图动画,将画布1和精灵1拖曳到界面中,并设置其高度和宽度。我们还需要设置精灵1的图片、X、Y和Z值。 第四步:编写代码。...

    项目经验-APP思维导图.png

    项目经验-APP思维导图.png

    png蕾丝.rar

    PNG(Portable Network Graphics)是一种无损压缩的位图格式,特别适合用于网页设计、图形编辑和数字艺术领域。PNG文件支持透明度,可以创建半透明效果,这在制作音画作品时非常有用,因为它允许背景和其他元素融合...

    C++生成背景透明PNG

    在这个场景下,我们有一个名为"Win32AppDemo"的压缩包文件,其中包含了一个基于Visual Studio 2010的测试项目,用于生成具有透明背景的PNG图像。下面将详细介绍这个过程涉及的知识点。 1. **PNG格式与Alpha通道**:...

    app测试用例完整版.png

    app测试用例完整版

    一起学——手机APP模块方案.png

    一起学——手机APP模块方案.png

    Bluetooth:这个APP是一个蓝牙演示,可以最终传输消息和文件

    BluetoothThis APP is a demo for bluetooth,which can transmit messages and files in the end.这是一个简单蓝牙APP,主要功能有扫描、配对;传输信息和文件。开发工具此APP开发的IDE为Android Studio 3.0APP截图

Global site tag (gtag.js) - Google Analytics