JPEGCrops scripts

Script description scribe

What is scripting?

As of JPEGCrops 0.7.0b, it is possible to get JPEGCrips to execute third party programs upon certain events. It's somewht of a stretch to call it scripting, but it's easier to understand than "event-driven third party program execution with parameters".

What are the events?

In the Scripts-panel in preferences, 4 events can be customized. They are:

JPEGCrops Start
This command will be executed upon program start.
Idea for use: Copy files from a memory card to a specific location.
Before crop
This command will be executed before all crops.
Idea for use: Uhmn... I don't know. Any suggestions?
After crop
This command will be executed after all crops.
Idea for use: Call a program that creates and embeds a thumbnail in the cropped file.
JPEGCrops close
This command will be executed upon program shutdown.
Idea for use: Start a program that performs a backup of the cropped files.

In the settings for each individual aspect, 2 events can be customized. They are:

Before crop
This command will be executed before crops, that uses the specific aspect.
Idea for use: Uhmn... I don't know. Any suggestions?
After crop
This command will be executed after crops, that uses the specific aspect.
Idea for use: Resize the cropped image to 700x500 pixels, so that it can be used on webpages.

A basic example

Let's make background images for computer desktops. We want the following:

We need ImageMagick

ImageMagick is a small collection of freeware command line based image manipulation programs. The official homepage is http://imagemagick.org/. If you're using Windows, go to the Binary Releases, scroll down to the bottom and download the Dynamic at 8 bits-per-pixel version. Be sure to enable Update executable search path in the install dialog.

Setup JPEGCrops

  1. Open the Settings dialog.
  2. Make sure that Advanced settings is checked.
  3. Press the Add...-button to add a new aspect.
  4. Fill in the Add new aspect dialog as shown on the screenshot below, press OK.
  5. Optional: Set the Default aspect to your new aspect (Background1024, if you followed the instructions verbatim), if you're planning on using the aspect a lot.
  6. No more work. That's it!

Main settings dialog Add new aspect dialog

When you open a new image in JPEGCrops and adjust the crop area, it should look like the screenshot below. When you press Crop, the image is cropped to the selected area and resized to 1024x768 pixels.

Main JPEGCrops window

What does the convert-thingie do?

The command was convert.exe %D -resize 1024x768> -quality 95 %D. Let's take a detailed look at that.

convert
This calls the command line program convert.exe from the ImageMagick program pack.
%D
The first %D gets expanded to the destination file, which convert.exe needs to know.
-resize 1024x768>
This tells convert.exe to resize the image to 1024x768 pixels, but only if the image is larger than that (that's what the > part does). Smaller images won't be resized.
-quality 95
This is the JPEG output quality. Don't go above 95, as is gives very little increase in quality and a huge increase in filesize.
%D
The second %D gets expanded to the same as the first %D. This means that convert.exe will override the file, instead of creating a new one. That's okay, as it is the destination file.

Free cropping

If you don't want to be restricted to the 4:3 aspect, but still want to resize the images to a maximum width or height, just choose Free size in the Add new aspect dialog.

It's not working!?

On some systems, Windows behaves in a strange way when it comes to resolving commands. At least it's strange to me. If the example above does not work, you might try one of the following:

  1. Check that ImageMagick is installed correctly: Open a command prompt and execute convert logo: logo.gif. A file with the name logo.gif should be created in the current directory.
  2. Rename convert.exe from ImageMagick: Locate convert.exe in the ImageMagick installation directory and make a copy with the name iconvert.exe, then change convert in the example above to iconvert.