Image Events で写真のサイズを変更する簡単な Applescript があります。写真はすべてサッカー選手なので、「1.jpg」「4.jpg」などの番号で名前が付けられています。私が遭遇する問題は、異なるディレクトリで複数のプレーヤーのバッチを実行すると、スクリプトが同じファイル名を持ち、以前に実行された別のチームの写真で上書きされることです。繰り返しますが、これらの写真はすべて別のディレクトリに配置されています。最終結果は、プレーヤーの再フォーマットされた写真が混乱することを 2、3 回正常に実行した後です。
これが、Image Events を呼び出すスクリプトの内容です。
on open some_items
repeat with this_item in some_items
try
rescale_and_save(this_item)
end try
end repeat
end open
to rescale_and_save(this_item)
tell application "Image Events"
launch
set the target_width to 290
-- open the image file
set this_image to open this_item
set typ to this_image's file type
copy dimensions of this_image to {current_width, current_height}
if current_width is greater than current_height then
scale this_image to size target_width
else
-- figure out new height
-- y2 = (y1 * x2) / x1
set the new_height to (current_height * target_width) / current_width
scale this_image to size new_height
end if
tell application "Finder" to set new_item to ¬
(container of this_item as string) & "" & (name of this_item)
save this_image in new_item as typ
end tell
end rescale_and_save