4.24.2008

AutoIt - 圖片批次裁剪

這隻程式會將script檔所在資料夾中的jpg檔全部裁剪後放到"new_pic"資料夾中


;批次裁剪圖片
#include "_PhotoCom.au3"

; Shows the filenames of all files in the current directory
$search = FileFindFirstFile("*.jpg")

; Check if the search was successful
If $search = -1 Then
MsgBox(0, "Error", "找不到相符的檔名&資料夾")
Exit
EndIf

DirCreate("new_pic")
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
;裁剪時需了解:
;(1) 1 點(像素)為 1/72英吋,即 1公分為28像素(此為word列印的標準)
; 參照http://office.microsoft.com/zh-tw/word/HP051896431028.aspx
;(2) 由_Photo_Info()傳回的值
; $pic_info[1] = 寬
; $pic_info[1] = 高
$new_file = StringReplace($file, ".jpg", "-copy"&".jpg")
$pic_info = _Photo_Info($file)
;剪下「左上」的0.5cm,「右下」的1cm
_Photo_Cutting($file,14, 14, $pic_info[1]-28, $pic_info[2]-28,@ScriptDir & "\new_pic\" & $new_file)
WEnd

; Close the search handle
FileClose($search)

沒有留言: