Skip to main content

用Python和PIL批量处理图片

还记得我前面那个体力活吧,千多张bmp要全部旋转90度,并保存为png。现在想起来真是太恐怖了,我居然是一张一张去做的。其实使用PythonPIL(Python Imaging Library),可以很简单的完成这类工作。

PIL并不是Python 2.5的默认包,需要另外安装。

#*coding=utf-8

import os
import Image

def ttimg(path):
    print 'process on:', path
    for name in os.listdir(path):
        if name != '.DS_Store':
            fullPath = os.path.join(path, name)
            if os.path.isfile(fullPath):
                (fileName, fileEx) = os.path.splitext(fullPath)
                if fileEx=='.bmp':
                    img = Image.open(fullPath)
                    new_img = img.rotate(270)
                    new_img.save(fileName+'.png')
            if os.path.isdir(fullPath):
                ttimg(fullPath)

if __name__ == '__main__':
    ttimg('/Users/xxx/pics/')
    print 'done.'

代码没有加亮,还有请顺便忽略ttimg()这种完全无意义的函数名。

Comments

Popular posts from this blog

Google Notebook整合了Google 书签

FF上一直装有Google笔记本的插件,一直没有到一面上去看,今天无意点到。发现多了个叫“Unfiled”的记事本,记得自己并未建过这么个东西,进去一看才发现,其实就是我的Google书签: 并且右下角也多了“Labels”,且与我Google书签中的相同。 其实人家的右上角的“ New features! ”里说得很清楚: Integration with Google Bookmarks Notebook is now integrated with Google Bookmarks. Your bookmarks will show up as a special Unfiled notebook, making Google Notebook a single place to collect and organize interesting web pages. To publish and collaborate, just drag and drop bookmarks into notebooks.

调用Response.Redirect时出现ThreadAbortException

调用Response.Redirect("test.aspx")时出现ThreadAbortException异常,是因为在内部调用Response.End(),而Response.End() 方法终止页的执行,并将此执行切换到应用程序的事件管线中的Application_EndRequest 事件。不执行 Response.End 后面的代码。可以使用 Response.Redirect ("test.aspx", false); 来代替。 更多情况请参考 PRB:在使用 Response.End、Response.Redirect或Server.Transfer时出现ThreadAbortException 适用于.net framework 1.0 1.1

PSP 三国无双 大蛇传 人物图片

PSP三国无双 大蛇传 人物图片(Google Picasa相册) 现在还不全,太多了。。。(2008-03-23) 搞完了,体力活啊。(2008-04-20) 暂时放弃吧,那个空间到期很久了,忘了更新这里了。什么时候找到地方放再跟新。(2009-04-29) 上传到Google Picasa(2009-09-25)