在 OSX Automator 白色背景而不是黑色中批量调整图像大小
Batch resizing images in OSX Automator white background instead of black
我正在使用 Automator 调整一堆图像的大小。除了将黑色背景添加到 PNG 图像之外,它的效果非常好。如果图像是具有透明背景的黑色徽标,这将是一个真正的问题。有什么办法可以改变背景颜色吗?
我正在使用裁剪图片操作。
干杯!
Automator
非常容易使用,但为了更有限的控制,您可以使用 AppleScript
(甚至作为 Automator
的一部分)和 Image Events
来做一些基本的图像编辑,包括使用具有特定尺寸和背景颜色的 pad
命令调整大小。这是一个基本脚本,您可以将其保存为 Script Editor
中的应用程序,然后,要使用它,请双击 Finder 中的应用程序图标,或者更好的是,将要处理的图像文件拖放到应用程序图标上:
property _width : 400
property _height : 200
property _color : {65528, 65535, 65525} --white
on run
open (choose file with multiple selections allowed)
end run
on open the_items
set output_folder to (((path to desktop) as string) & "Output")
try
get output_folder as alias
on error
tell application "Finder" to make new folder at desktop with properties {name:"Output"}
end try
repeat with this_item in the_items
set this_item to (this_item as alias)
set _info to info for this_item
set _extension to _info's name extension
if (_extension is in {"jpg", "jpeg", "tif", "tiff", "png"}) then
set _name to name of _info
set _name to (text 1 thru -((count _extension) + 1) of _name)
set output_path to (output_folder & ":" & _name & "jpg")
my resize_image(this_item, output_path, _width, _height)
end if
end repeat
end open
on resize_image(original_path, output_path, _width, _height)
tell application "Image Events"
launch
set _image to (open file (original_path as string))
pad _image to dimensions {_width, _height} with pad color _color -- use crop to dimensions to decrease the size
save _image as JPEG in file output_path with icon
close _image
end tell
end resize_image
这将在您的桌面上创建一个名为 Output 的文件夹(如果尚不存在)并使用脚本顶部的尺寸将图像保存为 JPG(您可以修改尺寸、颜色、输出位置)等,这只是一个例子)。
我正在使用 Automator 调整一堆图像的大小。除了将黑色背景添加到 PNG 图像之外,它的效果非常好。如果图像是具有透明背景的黑色徽标,这将是一个真正的问题。有什么办法可以改变背景颜色吗?
我正在使用裁剪图片操作。
干杯!
Automator
非常容易使用,但为了更有限的控制,您可以使用 AppleScript
(甚至作为 Automator
的一部分)和 Image Events
来做一些基本的图像编辑,包括使用具有特定尺寸和背景颜色的 pad
命令调整大小。这是一个基本脚本,您可以将其保存为 Script Editor
中的应用程序,然后,要使用它,请双击 Finder 中的应用程序图标,或者更好的是,将要处理的图像文件拖放到应用程序图标上:
property _width : 400
property _height : 200
property _color : {65528, 65535, 65525} --white
on run
open (choose file with multiple selections allowed)
end run
on open the_items
set output_folder to (((path to desktop) as string) & "Output")
try
get output_folder as alias
on error
tell application "Finder" to make new folder at desktop with properties {name:"Output"}
end try
repeat with this_item in the_items
set this_item to (this_item as alias)
set _info to info for this_item
set _extension to _info's name extension
if (_extension is in {"jpg", "jpeg", "tif", "tiff", "png"}) then
set _name to name of _info
set _name to (text 1 thru -((count _extension) + 1) of _name)
set output_path to (output_folder & ":" & _name & "jpg")
my resize_image(this_item, output_path, _width, _height)
end if
end repeat
end open
on resize_image(original_path, output_path, _width, _height)
tell application "Image Events"
launch
set _image to (open file (original_path as string))
pad _image to dimensions {_width, _height} with pad color _color -- use crop to dimensions to decrease the size
save _image as JPEG in file output_path with icon
close _image
end tell
end resize_image
这将在您的桌面上创建一个名为 Output 的文件夹(如果尚不存在)并使用脚本顶部的尺寸将图像保存为 JPG(您可以修改尺寸、颜色、输出位置)等,这只是一个例子)。