Skip to content

Home

Batch Crop Images using ImageMagick

Today, one of the tasks I performed involved batch cropping numerous pictures. I found ImageMagick to be very useful for scaling and cropping images. Mogrify, a command within the ImageMagick package, enables us to perform various operations on multiple images. I am posting this guide as a future reference for myself and perhaps it will be helpful for others as well.

Welcome back to another episode of Continuous Improvement, the podcast where we explore various tools and techniques for enhancing our productivity and achieving personal growth. I'm your host, Victor, and in today's episode, we'll be discussing an essential tool for image manipulation – ImageMagick. Specifically, we'll be focusing on the batch cropping feature using the Mogrify command. So without further ado, let's dive in!

Have you ever found yourself needing to resize or crop multiple images at once? It can be a time-consuming task if done manually, but fear not! ImageMagick is here to save the day. In today's episode, we'll guide you through the installation process and show you how to efficiently batch crop your images.

First things first, let's ensure that we have all the necessary dependencies installed. We recommend using MacPorts for this purpose. To install MacPorts, visit the official website at https://www.macports.org/install.php. Once installed, you might encounter an error message when using the port command. But don't worry, we have a solution for that too.

To resolve the error message, you'll need to update your shell's environment to work with MacPorts. Open your terminal and enter the following commands:

> _export PATH=$PATH:/opt/local/bin_
> _source .profile_
> _sudo port -v selfupdate_

Great! Now that we have MacPorts set up, let's move on to installing ImageMagick. You can find the installation files at http://www.imagemagick.org/script/binary-releases.php. Once you've downloaded the files, run the command:

> _sudo port install ImageMagick_

Sometimes, after installing ImageMagick, you might encounter an error message like "convert: command not found." Don't worry; we have a workaround for that too. Let's set the necessary environment variables. First, set the MAGICK_HOME variable to the path where you extracted the ImageMagick files:

> _export MAGICK_HOME="$HOME/ImageMagick-6.9.1"_

Next, ensure that the bin subdirectory of the extracted package is in your executable search path:

> _export PATH="$MAGICK_HOME/bin:$PATH"_

Lastly, set the DYLD_LIBRARY_PATH environment variable:

> _export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib"_

Now that we have ImageMagick successfully installed, let's move on to an optional step – adding a missing decoding library. If you come across an error message like "convert: no decode delegate for this image format," here's what you can do.

Firstly, visit http://www.imagemagick.org/download/delegates/ and download the required or missing delegate library, such as jpegsr9a.zip. Once downloaded, unzip the file and change your directory to the unzipped folder using the command cd jpeg-9a.

Now that we have everything set up, let's explore how to use ImageMagick and Mogrify for batch cropping your images. To avoid overwriting your original image files, it's always a good practice to create a new folder and back up your images there before performing any modifications.

If you want to resize a single image to a specific height while maintaining the aspect ratio, you can simply run the command:

> _convert input.png -geometry x600 output.png_

And if you'd like to convert all images in a folder to a certain height, change to that directory and use the command:

> _mogrify -geometry x600 *.png_

Need to scale down an image to a specific size? No problem! Just use the command:

> _convert myPhoto.jpg -resize 200x200^_

Looking to crop an image from the center? Easy! Just run the command:

> _convert myPhoto.jpg -gravity Center -crop 200x200+0+0 +repage newPhoto.jpg_

There are even more advanced options available. For instance, if you want to chop a certain portion from multiple images, you can use the command:

> _mogrify -gravity south -chop 0x135 *.jpg_

Additionally, if you need to resize all images in the current directory to a specific width while maintaining the aspect ratio, you can use the command:

> _mogrify -resize 800 *.jpg_

Lastly, if you wish to rotate multiple images by 90 degrees, you can leverage the power of ImageMagick with the command:

> _mogrify -rotate 90 *.jpg_

And that concludes our overview of using ImageMagick and the powerful Mogrify command for batch cropping and image manipulation. I hope you find this guide helpful in streamlining your image editing workflows.

If you're interested in diving deeper into ImageMagick and exploring its other capabilities, be sure to visit their official website at http://www.imagemagick.org.

That's it for today's episode of Continuous Improvement. Thank you for tuning in, and I hope you found this information valuable. If you have any questions or suggestions for future topics, feel free to reach out. Keep striving for continuous improvement, and until next time, happy cropping!

使用ImageMagick批量裁剪圖像

今天,我進行的任務之一涉及批量裁剪許多圖片。我發現ImageMagick在縮放和裁剪圖像方面非常有用。Mogrify,一個在ImageMagick包內的命令,使我們能夠對多個圖像進行各種操作。我發表這篇指南作為自己未來的參考,也許對其他人也有所幫助。

第一步:安裝MacPorts

https://www.macports.org/install.php

完成安裝後,如果你遇到以下錯誤:

> _sudo: port: command not found_

问题可能是因为MacPorts二进制文件安装在/opt/local/bin。你需要手動更新你的shell的環境以適配MacPorts:

> _export PATH=$PATH:/opt/local/bin_
> _source .profile_
> _sudo port -v selfupdate_

第二步:安裝 ImageMagick

http://www.imagemagick.org/script/binary-releases.php

執行以下命令進行安裝:

> _sudo port install ImageMagick_

port指令會下載ImageMagick和許多來自它的委託庫。如果你遇到像這樣的錯誤:

> _convert: command not found_

MAGICK_HOME環境變量設置為你提取ImageMagick文件的路徑:

> _export MAGICK_HOME="$HOME/ImageMagick-6.9.1"_

如果解壓包的bin子目錄還不在你的可執行搜尋路徑中,添加它:

> _export PATH="$MAGICK_HOME/bin:$PATH"_

設置DYLD_LIBRARY_PATH環境變量:

> _export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib"_

第三步:添加遺失的解碼庫

如果你嘗試轉換JPEG圖像並獲得以下錯誤消息:

> _“convert: no decode delegate for this image format”_

1.訪問 http://www.imagemagick.org/download/delegates/ 下載需要的或缺失的代理庫,如jpegsr9a.zip。 2.解壓縮該檔案。 3.更改目錄到解壓縮後的文件夾:

> _cd jpeg-9a_

4.然後執行:

> _./configure; make; make test; make -n install_

第五步:使用方式

為了避免覆蓋原始圖像文件,創建一個新文件夾,並在那裡備份圖像。

如果要將一個單獨的圖像大小調整為600px的高度,同時保持相同的縱橫比,運行:

> _convert input.png -geometry x600 output.png_

如果你想轉換文件夾中的所有圖像,更改到該目錄並使用:

> _mogrify -geometry x600 *.png_

要將圖像縮小到200像素:

> _convert myPhoto.jpg -resize 200x200^_

從圖片中央裁剪圖片:

> _convert myPhoto.jpg -gravity Center -crop 200x200+0+0 +repage newPhoto.jpg_

-gravity south選項指定裁剪應該從圖像的底部開始。-chop 0x135選項從高度中切割135個像素:

> _mogrify -gravity south -chop 0x135 *.jpg_

要將當前目錄中的所有圖像大小調整為800的寬度(高度將按比例減少):

> _mogrify -resize 800 *.jpg_

要旋轉圖片90度:

> _mogrify -rotate 90 *.jpg_

閱讀更多:

請訪問 http://www.imagemagick.org.

Switching from Sublime Text to Atom

The Atom text editor has just released its 1.0 version. There are plenty of reasons to switch from Sublime Text. Maybe you love the concept of open source, or perhaps you're a member of the GitHub community. While Atom does have a different look and feel, installing the following packages can quickly bring your productivity back up to speed.

1. Install the Monokai Syntax Theme

There are many cool-looking themes, but I'm accustomed to Sublime's default color scheme. Install the Monokai syntax theme by visiting:

https://atom.io/themes/monokai

2. Convert Tabs to Spaces

Install the "tabs-to-spaces" package by going to:

https://atom.io/packages/tabs-to-spaces

Then add this line to your config.cson:

'tabs-to-spaces': 'onSave': 'untabify'

3. Soft Tabs

By default, hard tabs are 4 characters long, which can result in code that is hard to read due to excessive indentation. I recommend enabling the "Soft Tabs" option in the user settings, which replaces tabs with spaces.

4. Show White Space

In Settings, check the box labeled "Show Invisibles." This will add little dots to indicate indentation spaces.

5. Trim Trailing White Space on Save

This feature strips trailing whitespace and adds a trailing newline when the editor is saved.

https://atom.io/packages/whitespace

6. Bracket Highlighter

"Bracket-matcher" is a must-have package for highlighting all sorts of brackets: () [] {} "" '' <>.

https://github.com/atom/bracket-matcher

7. Emmet

Emmet is an essential toolkit for web developers. It saves a lot of time with shortcuts. For instance, type the following and then hit tab:

div#container>ul>li.item

This will output the appropriate HTML tags.

Another example: start typing lorem and it will automatically output the entire "Lorem Ipsum" text.

https://github.com/emmetio/emmet-atom

8. Git Plus

This package allows you to perform Git operations without needing to open the terminal, right from the Atom Editor. Save a few seconds off your workflow by using this package:

https://atom.io/packages/git-plus

9. Git Diff

This feature marks lines in the editor gutter that have been added, edited, or deleted since the last commit:

https://github.com/atom/git-diff

10. Linter and JSHint

To lint your code, visit:

https://atom.io/packages/linter

For JSHint, go to:

https://atom.io/packages/linter-jshint

11. Alignment

This package offers a simple key-binding for aligning multi-line, multi-cursor, and multiple selections. For example, before and after using the shortcut ctrl+cmd+a:

Before:

var a = b;
var ab = c;
var abcd = d;
var ddddd = d;

After:

var a     = b;
var ab    = c;
var abcd  = d;
var ddddd = d;

https://atom.io/packages/atom-alignment

12. Set Atom as Git's Default Editor

If you're not comfortable using Vim for writing Git commits, you can set Atom as the default editor by executing the following command:

git config --global core.editor "atom --wait"

Packages offer developers tools to enhance productivity and workflow. What packages have you installed? Let me know what your favorites are.

Switching from Sublime Text to Atom

The Atom text editor has just released its 1.0 version. There are plenty of reasons to switch from Sublime Text. Maybe you love the concept of open source, or perhaps you're a member of the GitHub community. While Atom does have a different look and feel, installing the following packages can quickly bring your productivity back up to speed.

1. Install the Monokai Syntax Theme

Hello, and welcome to "Continuous Improvement", the podcast where we explore tools and strategies for enhancing productivity and efficiency in our daily lives. I'm your host, Victor, and in today's episode, we're diving into the world of text editors. Specifically, we'll be talking about the recent release of Atom 1.0 and why it might be time to consider making the switch from Sublime Text. But don't worry if you're already an Atom user, because I'll also be sharing some essential packages to boost your productivity. So, let's get started!

Atom has gained quite a following, especially among those who appreciate open-source software and are members of the GitHub community. If you're not familiar with Atom, it's a highly customizable text editor that offers an intuitive interface and a range of features. However, for those transitioning from Sublime Text, there might be a slightly different look and feel to get used to. But fear not, because with the right packages, we can quickly bring your productivity back up to speed. So, let's jump in!

The first package I recommend installing is the Monokai Syntax Theme. While there are many cool-looking themes available, if you're accustomed to Sublime's default color scheme, the Monokai syntax theme will provide a similar familiar feel. You can easily install it by visiting the Atom theme website.

Next up, let's talk about tabs versus spaces. If you prefer spaces over tabs (or vice versa), the "tabs-to-spaces" package is a must-have. It allows you to easily convert tabs to spaces and vice versa within your code files. To install this package, simply navigate to the Atom package website and download it. And don't forget to add the necessary line to your config.cson file, as mentioned in the installation instructions.

Now let's tackle the issue of excessive indentation. By default, Atom uses hard tabs that are four characters long. But this can result in code that's hard to read. That's why I recommend enabling the "Soft Tabs" option in the Atom user settings. By doing so, your editor will automatically replace tabs with spaces, resulting in a more readable code structure.

Have you ever struggled to identify indentation spaces in your code? Well, I have good news for you. Atom provides a feature called "Show Invisibles" that allows you to visualize whitespace characters. To enable this feature, head to the Atom settings and check the box labeled "Show Invisibles." It'll add little dots to indicate indentation spaces, making your code easier to read and manage.

Now, let's talk about keeping your code clean and organized. The "whitespace" package is a great tool that trims trailing white space and adds a trailing newline when you save your file. This not only maintains a consistent format but also eliminates unnecessary whitespace. You can find and install this useful package from the Atom package website.

Highlighting brackets in your code is essential for efficient coding. Thankfully, the "bracket-matcher" package is here to help. It allows you to easily match brackets, parentheses, square brackets, quotation marks, and more. This package helps you navigate and identify code blocks with ease. You can find and install the bracket-matcher package from the official Atom GitHub repository.

If you're a web developer, you'll love our next package recommendation. Meet the Emmet toolkit. Emmet is an essential time-saving tool that provides shortcuts for generating HTML and CSS code. For example, by typing a simple line of code and hitting the tab key, Emmet can quickly generate commonly used HTML tags. Additionally, it also supports generating placeholder text like "Lorem Ipsum." You can activate Emmet by installing the "emmet-atom" package from the official GitHub repository.

Let's move on to making your Git workflow more efficient. The "Git Plus" package allows you to perform Git operations directly from within the Atom editor, saving you precious time and eliminating the need to switch back and forth between the editor and the terminal. Say goodbye to unnecessary steps and friction in your Git workflow by installing this package from the Atom package website.

Have you ever wanted to see the changes you've made since your last commit directly in your code editor? Well, the "Git Diff" package does exactly that. It marks lines in the editor gutter that have been added, edited, or deleted since the last commit, providing a visual representation of your changes. This package can be installed from the official Atom GitHub repository.

Code linting is an important practice for developers, and luckily, Atom offers a powerful package called "Linter" that enables code linting across a range of programming languages. To get started, install the "linter" package from the Atom package website. Additionally, if you're a JavaScript developer, the "linter-jshint" package provides JSHint integration for Atom. Install this package as well to enhance your JavaScript linting capabilities.

Are you tired of manually aligning multiple lines or selections in your code? The "atom-alignment" package is here to make your life easier. With a simple key-binding, it aligns multi-line, multi-cursor, and multiple selections in your code. This package can be easily found and installed from the Atom package website.

Finally, for all the Git users out there, if you're not comfortable using Vim as your default editor for writing Git commits, I have a quick tip for you. Execute the following command in your terminal to set Atom as your default editor for Git commits: "git config --global core.editor 'atom --wait'". This will open up Atom whenever you're writing a commit message, ensuring a seamless workflow.

And there you have it, 12 essential Atom packages to enhance your productivity and workflow. Whether you're a seasoned Atom user or considering making the switch from Sublime Text, these packages are sure to boost your coding experience. Have you installed any of these packages, or do you have other favorites that you'd like to share? I'd love to hear from you. Reach out to me on Twitter @victor_continuous and let's keep the conversation going.

That concludes today's episode of "Continuous Improvement". I hope you found these Atom packages helpful and that they empower you to take your coding skills to new heights. As always, stay tuned for more episodes where I'll continue to explore the tools and strategies for making continuous improvements in our lives. Until next time, I'm Victor signing off. Happy coding!

從Sublime Text切換到Atom

Atom文本編輯器剛剛發布了其1.0版本。有很多理由從Sublime Text切換過來。也許你熱愛開源的概念,或者你是GitHub社區的一員。雖然Atom有著不同的外觀和感覺,但安裝以下的包可以快速提高你的生產力。

1. 安裝Monokai語法主題

有很多酷炫的主題,但我習慣於Sublime的默認色彩方案。通過訪問以下頁面,安裝Monokai語法主題:

https://atom.io/themes/monokai

2. 將標籤轉換為空格

通過前往以下網址安裝"tabs-to-spaces"包:

https://atom.io/packages/tabs-to-spaces

然後在您的設定 cson 文件中添加這行代碼:

'tabs-to-spaces': 'onSave': 'untabify'

3. 軟標籤

默認情況下,堅硬的標籤為4個字符長,這可能導致由於過多的縮進而使代碼難以閱讀。我建議在用戶設定中啟用"Soft Tabs"選項,這將用空格替換標籤。

4. 顯示空白位

在設定中,勾選"Show Invisibles"。這將在代碼中加入小點來顯示縮進空格。

5. 在保存時修剪尾隨的空白位

這個功能會在保存編輯器時去掉尾隨的空格並添加一個尾隨的換行。

https://atom.io/packages/whitespace

6. 括號高亮

"Bracket-matcher"是一個必需的包,用於高亮各種括號:() [] {} "" '' <>。

https://github.com/atom/bracket-matcher

7. Emmet

Emmet對網頁開發者來說是必不可少的工具包。它可以用快捷方式節省大量時間。例如,輸入以下的代碼然後按Tab鍵:

div#container>ul>li.item

這將輸出相應的HTML標籤。

另一個例子:開始輸入lorem,它會自動輸出整個"Lorem Ipsum"文本。

https://github.com/emmetio/emmet-atom

8. Git Plus

此包允許您在Atom Editor內進行Git操作,無需打開終端,節省了您的工作流程的一些時間:

https://atom.io/packages/git-plus

9. Git Diff

此功能在編輯器的邊界標識出自上次提交以來被添加、編輯或刪除的行:

https://github.com/atom/git-diff

10. Linter和JSHint

要檢查您的代碼,請訪問:

https://atom.io/packages/linter

對於JSHint,請前往:

https://atom.io/packages/linter-jshint

11. Alignment

此包提供了一個簡單的鍵綁定,用於對齊多行、多光標和多選擇。例如,使用快捷鍵ctrl+cmd+a的前後對比:

Before:

var a = b;
var ab = c;
var abcd = d;
var ddddd = d;

After:

var a     = b;
var ab    = c;
var abcd  = d;
var ddddd = d;

https://atom.io/packages/atom-alignment

12. 將Atom設定為Git的預設編輯器

如果你不習慣使用Vim撰寫Git提交,可以通過執行以下命令將Atom設為預設編輯器:

git config --global core.editor "atom --wait"

包提供了開發人員提高生產力和工作流程的工具。你安裝了哪些包?告訴我你的最愛是什麼。

How to Upgrade Your Ghost Blog via Command Line

Step 1: Navigate to Your Ghost Blog Directory

First, change the directory to the path where your Ghost blog is installed. For example, in my case, it's located at:

cd /var/www

Step 2: Download the Latest Version with wget

Use wget to download the latest version of Ghost:

wget https://ghost.org/zip/ghost-X.X.X.zip

Note: You can find the current version on the official website: https://ghost.org/download/

Step 3: Remove the Old Core Code

Delete the old core directory:

rm -rf ghost/core

Step 4: Unzip the Downloaded File

Unzip the file you downloaded into the ghost directory:

unzip -uo ghost-0.6.4.zip -d ghost

Step 5: Change Ownership and Permissions

Update the ownership and permissions for the Ghost files:

chown -R ghost:ghost ghost/

Step 6: Install New Dependencies

Navigate back to your Ghost directory and install new dependencies:

cd /var/www/ghost
npm install

Step 7: Restart Ghost

Finally, restart your Ghost blog:

pm2 restart ghost

Note: If you're not using pm2, you can use the following command instead:

service ghost start

Your Ghost blog should now be successfully upgraded!


How to Upgrade Your Ghost Blog via Command Line

Welcome to "Continuous Improvement," the podcast where we explore tips, tricks, and strategies for improving and optimizing various aspects of our lives. I'm your host, Victor, and in today's episode, we're going to discuss how to upgrade your Ghost blog to the latest version. So if you're a Ghost blog owner and want to make sure you have all the latest features and bug fixes, this episode is for you.

Before we dive into the steps, make sure you have access to your Ghost blog directory. This is where all your Ghost files are stored. Once you're ready, let's get started!

Step 1 is to navigate to your Ghost blog directory. In your terminal, change the directory to the path where your Ghost blog is installed. For example, if your blog is located at /var/www, you can use the command:

cd /var/www

Great! Now that we're in the right directory, step 2 is to download the latest version of Ghost using the wget command. You can find the current version on the official Ghost website at https://ghost.org/download/. Once you have the download link, use wget followed by the link to download the latest version.

Awesome! Now that we have the latest version of Ghost downloaded, let's move on to step 3. In this step, we need to remove the old core code. Use the following command to delete the old core directory:

rm -rf ghost/core

We're making progress! Step 4 is all about unzipping the downloaded file into the Ghost directory. Use the command unzip -uo ghost-X.X.X.zip -d ghost, where X.X.X represents the version number you downloaded. This will extract the files and overwrite any existing ones.

Moving on to step 5, we need to update the ownership and permissions for the newly added Ghost files. This helps ensure everything works smoothly. Use the command chown -R ghost:ghost ghost/ to update the ownership.

Step 6 is an important one. We need to install new dependencies for the upgraded Ghost version. Navigate back to your Ghost directory using cd /var/www/ghost and run npm install to install the new dependencies.

Fantastic! We're almost there. In step 7, it's time to restart your Ghost blog to complete the upgrade process. Use the command pm2 restart ghost if you're using pm2. If not, you can try service ghost start instead.

And there you have it! Your Ghost blog should now be successfully upgraded to the latest version. Remember, keeping your blog up to date ensures you have access to all the latest features and bug fixes.

That brings us to the end of this episode of "Continuous Improvement." I hope you found these steps helpful in upgrading your Ghost blog. If you have any questions or suggestions for future episodes, feel free to reach out to me. Until next time, keep improving and optimizing!

如何透過命令行升級您的Ghost博客

步驟1:導航至您的Ghost博客目錄

首先,將目錄更改為您的Ghost博客安裝的路徑。例如,在我的情況下,它位於:

cd /var/www

步驟2:使用wget下載最新版本

使用wget下載Ghost的最新版本:

wget https://ghost.org/zip/ghost-X.X.X.zip

注意:您可以在官方網站上找到當前的版本:https://ghost.org/download/

步驟3:移除舊的核心代碼

刪除舊的核心目錄:

rm -rf ghost/core

步驟4:解壓下載的文件

將您下載的文件解壓縮到ghost目錄:

unzip -uo ghost-0.6.4.zip -d ghost

步驟5:變更所有權和權限

更新Ghost文件的所有權和權限:

chown -R ghost:ghost ghost/

步驟6:安裝新的依賴關係

返回到您的Ghost目錄並安裝新的依賴關係:

cd /var/www/ghost
npm install

步驟7:重新啟動Ghost

最後,重新啟動您的Ghost博客:

pm2 restart ghost

注意:如果您不使用pm2,則可以使用以下命令:

service ghost start

您的Ghost博客現在應該已成功升級!


SSH: How to Fix the 'Unprotected Private Key' Error

The Problem

When I downloaded the .pem file to SSH into my AWS instance, I encountered the following error:

WARNING: UNPROTECTED PRIVATE KEY FILE!

Permissions 0640 for 'blog.pem' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. Bad permissions: ignore key: blog.pem Permission denied (publickey).

The Solution

To resolve this issue, run the following command in your terminal:

ssh -i xxx.pem root@52.74.3.53

Replace xxx.pem with the name of your .pem file.

This command will modify the permissions on the keys, making them readable only by you.

SSH: How to Fix the 'Unprotected Private Key' Error

The Problem

Hello, and welcome to "Continuous Improvement," the podcast where we explore tips, tricks, and solutions for everyday problems. I'm your host, Victor. In today's episode, we'll be discussing a common issue encountered when attempting to SSH into an AWS instance. We'll explore the error message and provide step-by-step instructions to resolve it. So let's dive right in!

Have you ever come across the following error message when trying to SSH into your AWS instance?

"WARNING: UNPROTECTED PRIVATE KEY FILE! Permissions 0640 for 'blog.pem' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. Bad permissions: ignore key: blog.pem Permission denied (publickey)."

This error message may seem complex at first, but fear not! I have a simple solution for you. By following a few steps, we can quickly resolve this issue.

Step one, open your terminal, and navigate to the location of your .pem file.

Step two, once you're in the correct directory, run the following command:

"ssh -i xxx.pem root@52.74.3.53"

Make sure to replace xxx.pem with the name of your specific .pem file.

This command will modify the permissions on the keys, making them readable only by you. Once you've done that, you should be able to SSH into your AWS instance without any issues.

And just like that, you've successfully resolved the pesky permissions error that was preventing you from accessing your AWS instance. Remember, continuous improvement is all about finding solutions to everyday problems and making our lives easier.

I hope you found this episode helpful. If you have any questions or suggestions for future episodes, feel free to reach out. Thank you for tuning in to "Continuous Improvement." I'm your host, Victor, and until next time, keep learning, keep improving. Goodbye!