我有一个简单的 Applescript 可以使用图像事件调整照片的大小。这些照片都是足球运动员,所以他们都以他们的号码命名,如“1.jpg”、“4.jpg”等。我遇到的问题是,当我在不同目录中执行多批玩家时,脚本将用来自另一个团队的具有相同文件名且之前完成的照片覆盖一张照片。同样,这些照片都放在不同的目录中。最终的结果是在成功运行两三遍后,重新格式化的球员照片会变得混乱。
这是我在脚本中调用图像事件的内容。
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