AppleScript:将图像切成两半?

发布于 2024-12-09 02:10:01 字数 39 浏览 0 评论 0原文

是否可以使用 AppleScript 将图像切成两半并单独保存?

Is it possible to cut an image in the half using AppleScript and save them seperately?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怀念你的温柔 2024-12-16 02:10:01

使用 ImageMagick 会更容易。这会将左半部分保存为 input-0.png,将右半部分保存为 input-1.png

convert input.png -crop 50%x100% +repage input.png

这会将右半部分保存为 right.png< /code>:

convert input.png -gravity east -crop 50%x100% +repage right.png

+repage 删除旧画布大小的元数据。请参阅http://www.imagemagick.org/Usage/crop/

您可以使用 brew install imagemagicksudo port install imagemagick 安装 ImageMagick。

It would be easier to use ImageMagick. This saves the left half as input-0.png and the right half as input-1.png:

convert input.png -crop 50%x100% +repage input.png

This saves just the right half as right.png:

convert input.png -gravity east -crop 50%x100% +repage right.png

+repage removes metadata for the old canvas size. See http://www.imagemagick.org/Usage/crop/.

You can install ImageMagick with brew install imagemagick or sudo port install imagemagick.

却一份温柔 2024-12-16 02:10:01

如果您无法访问可编写脚本的图像编辑应用程序(如 Photoshop 中的应用程序),则可以使用 Mac OS X 附带的图像事件来裁剪图像。要获取图像的尺寸,只需使用类似以下的内容...

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}

会有所不同 :命令,但这些是必需的参数。其他应用程序很可能有不同的实现(可能更像苹果的)。只需选择您选择的图像编辑应用程序,然后仔细阅读词典以了解其工作原理。

You can use Image Events, which comes with Mac OS X to crop an image if you don't have access to a scriptable image-editing application (as in Photoshop). To get the dimensions of the image just use something like the following...

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

...and the command to crop the image is as simple as

crop pathToFile to dimensions {cropWidth, cropHeight}

If, by chance, you have Photoshop, then cropping is handled differently:

crop pathToFile bounds {cropLeft, cropTop, cropRight, cropBottom}

There is more to the command but those are the required parameters. Other applications will most likely have a different implementation (probably more like Apple's). Just select your image-editing app of choice, and peruse the Dictionary to see how it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文