AppleScript:将图像切成两半?
是否可以使用AppleScript将图像切成两半并分别保存?如果无法访问可编写脚本的图像编辑应用程序(如Photoshop),可以使用Mac OS X附带的图像事件来裁剪图像。要获得图像的尺寸,只需使用以下内容AppleScript:将图像切成两半?,applescript,image-manipulation,cut,Applescript,Image Manipulation,Cut,是否可以使用AppleScript将图像切成两半并分别保存?如果无法访问可编写脚本的图像编辑应用程序(如Photoshop),可以使用Mac OS X附带的图像事件来裁剪图像。要获得图像的尺寸,只需使用以下内容 on GetImageDimensions(TheFile) -- (file path as string) as {width, height} try tell application "Image Events" launch --
on GetImageDimensions(TheFile) -- (file path as string) as {width, height}
try
tell application "Image Events"
launch --we have to launch Image Events before we can use it
set theImage to open TheFile
set theImageDimensions to dimensions of theImage
set theImageWidth to item 1 of theImageDimensions
set theImageHeight to item 2 of theImageDimensions
return {theImageWidth, theImageHeight}
end tell
on error
return {-1, -1} // just in case something goes wrong
end try
end GetImageDimensions
…裁剪图像的命令非常简单
crop pathToFile to dimensions {cropWidth, cropHeight}
如果您碰巧有Photoshop,则裁剪的处理方式不同:
crop pathToFile bounds {cropLeft, cropTop, cropRight, cropBottom}
命令还有更多内容,但这些是必需的参数。其他应用程序很可能会有不同的实现(可能更像苹果的)。只需选择您选择的图像编辑应用程序,并仔细阅读字典,看看它是如何工作的。这样会更容易使用。这将左半部分保存为input-0.png
,右半部分保存为input-1.png
:
convert input.png -crop 50%x100% +repage input.png
convert input.png -gravity east -crop 50%x100% +repage right.png
这只将右半部分保存为right.png
:
convert input.png -crop 50%x100% +repage input.png
convert input.png -gravity east -crop 50%x100% +repage right.png
+repage
删除旧画布大小的元数据。看
您可以使用
brew安装ImageMagick
或sudo端口安装ImageMagick
安装ImageMagick,这是绝对推荐的。您甚至可以在applescript中通过DoShell脚本
运行该脚本。