2019年4月10日 星期三

Merge Images with ImageMagick & Automator


"Merge Image" is an Automator workflow to automatise the image combination tasks on macOS.

"Merge Image" 是一個 Automator 工作流程,用來將合併影像檔的流程自動化。

Image combination is a built-in feature on iOS, officially supported by Siri Shortcuts. However, there is no similar Automator action (even AppleScript codes) or any supported feature in Preview.app or Photos.app. So, I integrate the power of ImageMagick into this Automator workflow, to achieve image combinations with two modes: "Side by side" and "Grid".

在 iOS 上,"合併影像檔" 是一個由 Siri 捷徑官方支援的內建功能。然而,在 macOS 上沒有類似的 Automator 動作 (甚至 AppleScript 也不支援),而 "預覽程式" 及 "照片" 裡也沒有支援此功能。所以我將 ImageMagick 的功能整合進 Automator 工作流程以達成類似的效果,其分為兩種模式:"並排" (Side by side) 及 "網格" (Grid)。

Because the technical core of this workflow is ImageMagick, it needs to be installed first. In addition, please check if the installed commands "convert" and "mogrify" is located in /usr/local/bin/ [1]. If yes, you are all set; if not, e.g. in /XXX/YYY/, please change all statements including "convert" and "mogrify" from "/usr/local/bin/convert (mogrify) ...." to "/XXX/YYY/convert (mogrify) ....". Another way, make alias of "convert" and "mogrify" and then put them into the directory /usr/local/bin/.

由於此工作流程的技術核心是 ImageMagick,所以必須先安裝它。此外,請確認 ImageMagick 的指令 "convert" 及 "mogrify" 是否存在 /usr/local/bin/ 資料夾裡 [1],如果是,那設定已完成;如果不是,比如其存在於 /XXX/YYY/ 資料夾內,請修改所有包含 "convert" 及 "mogrify" 的語句,從 "/usr/local/bin/convert (mogrify) ...." 變成 "/XXX/YYY/convert (mogrify) ...."。另一個方法是,製作 "convert" 及 "mogrify" 的替身,然後將其放入 /usr/local/bin/ 資料夾。

Go to /usr/local/bin/ to check "convert" and "mogrify" command.


How to install (如何安裝)

1. Install ImageMagick. You can download the package file and set the parameters for installation manually, but I suggest you to use MacPort (sudo port install ImageMagick) or Homebrew (brew install imagemagick) for the automatic installation (I use Homebrew) [2].

1. 安裝 ImageMagick。你可以下載安裝包且手動設定參數,但我建議使用 MacPort (sudo port install ImageMagick) 或 Homebrew (brew install imagemagick) 以進行自動安裝 (我使用的是 Homebrew) [2]。

2. No more step, just use "Merge Images" as a normal Automator workflow.

2. 沒有其他步驟了,就把 "Merge Images" 當作一般的 Automator workflow 使用吧!


How to use (如何使用)



From the above Automator flow, the logic is simple:

從上圖的 Automator 工作流程,其邏輯非常簡單:

1. Put the image files into "Get Specified Finder Items" action, and sort them.

1. 將影像檔放入 Automator 動作 "獲取特定 Finder 項目" 中,而且將其排序。

2. Set the final name in "Rename Finder Items" action, as you like.

2. 依自己喜好在 "重新命名 Finder 項目" 中設定最終合併檔的檔名。

3. Run this workflow with the play button at the up-right corner.

3. 以右上角的播放按鈕執行此工作流程。

4. Choose the merge mode.

4. 選擇合併模式。


5-1. Side by side: choose the merge direction ("Horizontal": left to right; "Vertical": Up to down).

5-1. 並排:選擇合併方向 ("水平":左往右;"垂直":上到下)。


5-2. Grid: assign the merge layout.

5-2. 網格:指定合併的版面排列方式。


For example, the case "3X2" is as below (notice the file order):

例如 "3X2" 則為以下的排列 (注意檔案的排序方式):


6. Check the final result. If you find any bug or you have any question about this Automator workflow, please leave your comment on below, thanks!

By the way, please remember this program is an Automator workflow, which means that you could add other actions for further image processing, such as resize, rotate, crop ..... and so on, enjoy!

6. 確認最終的合併結果。如果發現任何問題或有任何建議,請在下面留言,多謝!

附帶一提,別忘了這個程式是個 Automator 工作流程,所以你可以加入其他動作,例如圖片調整大小、旋轉、裁切 ..... 等等,以進行更進一步的影像處理。



Notes
1. You might find that a small arrow is attached to the file in /usr/local/bin/. It's the symbol of "alias" of that file, which is similar with the file shortcut on Windows.

1. 你也許發現在 /usr/local/bin/ 內的檔案附有一個小箭頭,這是檔案 "替身" 的標誌,類似於 Windows 的檔案捷徑。

2. Because ImageMagick is a popular image processing engine, many softwares are actually powered by it and already "help" you to install it without your notices. So, check the folder /usr/local/bin/ before you start to install it.

2. 由於 ImageMagick 是一個很熱門的圖像處理引擎,故很多軟體實際上是借用它的功能,且在不引起使用者注意的情況下已經幫你安裝了。所以,在開始安裝前請務必先確認 /usr/local/bin/ 資料夾中是否有已經安裝的 "convert" 及 "mogrify" 指令。

沒有留言:

張貼留言