產生個人頭像的 applescript droplet

本區專門提供 Mac OS X 使用者交換使用心得

版主: ross_ttbryanchangdigdogchester

回覆文章
內容
發表人
留言五百如一日
文章: 610
註冊時間: 12/25/2001 1:01 am

產生個人頭像的 applescript droplet

#1 文章 »

昨天在冰果室閑逛,才發現會員可上傳個人頭像;小弟冒昧,寫了一個 applescript droplet,以製作一個符合要求的圖檔。

使用略述:

一 雙點擊此 droplet,選取圖檔;或,把一個圖檔拖放在此 droplet 上。

二 兩個小圖檔會產生在桌面上,其一的 icon 為圖檔內容,檢視效果用;其二、檔名以 "noRt" 開首,繼之以一組 8 位數目字,及綴以該檔格式的小圖檔才是符合冰果室要求,上傳用。

三 此 droplet 只按比例縮小原圖檔,如欲一 80 x 80 像素的小圖檔,可先用 iPhoto 裁切一個正方形的圖檔。

可自行編譯以下指令,儲存為 application;或在小弟的 iDisk 內下載 TIG.dmg。


http://homepage.mac.com/cherish/FileSharing1.html


代碼: 選擇全部

property thumbsize : 80
property fileTypeList : {"JPEG", "TIFF", "GIFf", "PICT", "QTIF"}
property fileTEList : {".jpg", ".tif", ".gif", ".pct", ".qtif"}
property extensionList : {".jpg", ".jpeg", ".tif", ".tiff", ".gif", ".pict", ".pct", ".qtif"}

-- if someone double click this droplet
-- it will ask for the image file
on run
	set imageOri to (choose file with prompt "where is the image?")
	resizeImage(imageOri)
end run

--when a image is being droped on this droplet
-- the dropped file
on open theFile
	set imageOri to item 1 of theFile
	resizeImage(imageOri)
end open

on resizeImage(theImage)
	tell application "Finder"
		try
			set theFileType to (file type of theImage) as string
		on error
			set theFileType to ""
		end try
		set theFileName to name of item theImage
	end tell
	
	set itsAnImage to false
	if theFileType is in fileTypeList then set itsAnImage to true
	repeat with i in extensionList
		if theFileName ends with i then
			set itsAnImage to true
			set imageExt to i
		else
			repeat with i from 1 to count of fileTypeList
				if theFileType = item i of fileTypeList then
					set imageExt to item i of fileTEList
				end if
			end repeat
		end if
	end repeat
	set thumbName to "t" & (random number from 10000000 to 99999999)
	set thumbPath to (path to desktop folder as string) & thumbName & imageExt
	try
		tell application "Image Capture Scripting"
			set newThumb to open theImage
			scale newThumb to size thumbsize
			save newThumb in file thumbPath
			close newThumb
		end tell
	end try
	try
		do shell script "cp ~/Desktop/" & thumbName & imageExt & " ~/Desktop/noR" & thumbName & imageExt
	end try
end resizeImage
頭像
bryanchang
討論區管理員
文章: 7057
註冊時間: 04/19/2001 1:01 am
來自: The '60s
聯繫:

#2 文章 bryanchang »

哈~感謝悲兄。

不過上傳的頭像檔名不用是隨機的,因為在網上出現的都是由 php 產生所的隨機檔名。

Bryan
圖檔
留言五百如一日
文章: 610
註冊時間: 12/25/2001 1:01 am

#3 文章 »

眼利 :)

這個嗎... 隨機的檔名可省卻檢查同名檔案或資料夾已存在否;及避免 shell command cp 遇上中文檔名時的錯誤。

遊戲之作,見笑。
頭像
bryanchang
討論區管理員
文章: 7057
註冊時間: 04/19/2001 1:01 am
來自: The '60s
聯繫:

#4 文章 bryanchang »

悲兄太客氣了,其實我最近也寫了一個類似的 AppleScript,我準備稍後貼一篇文章介紹
圖檔
留言五百如一日
文章: 610
註冊時間: 12/25/2001 1:01 am

#5 文章 »

有搶鮮 preview 版嗎?
頭像
bryanchang
討論區管理員
文章: 7057
註冊時間: 04/19/2001 1:01 am
來自: The '60s
聯繫:

#6 文章 bryanchang »

有的,已經寄到你的 mac.com 信箱了。

Bryan
圖檔
留言五百如一日
文章: 610
註冊時間: 12/25/2001 1:01 am

#7 文章 »

已回郵;第一點已可,請試試。
回覆文章