CROPTOOL(1) General Commands Manual CROPTOOL(1)

croptoolmass image cropping tool

croptool [-mr] [-f format] [-w width] [-c padding] [-p color] [-s color] [-z size] file ...

croptool shows each of the given images and allows a cropping rectangle to be drawn. On exit, the cropping command is printed for each of the files. If a file was skipped, nothing is printed for it.

Disable automatic redrawing when the window is resized (the -m stands for 'manual'). This may be useful on older machines that start accelerating global warming when the image is redrawn constantly while resizing. Note that this also disables exposure events, so the window has to be manually redrawn when switching back to it from another window.
Disable automatic redrawing while the cropping box is being dragged or resized, for the same reason as -m.
format
Set the format to be used when the cropping commands are output. See OUTPUT FORMAT for details.
width
Set the line width of the cropping rectangle in pixels (valid values: 1-99). Default: 2.
padding
Set the amount of padding used for collision with the mouse in pixels. This determines how far away the mouse pointer has to be from an edge or corner of the cropping rectangle to collide with it (valid values: 1-99). Default: 10.
color
Set the primary color for the cropping rectangle. Default: #000000.
color
Set the secondary color for the cropping rectangle. Default: #FFFFFF.
size
Set the Imlib2 in-memory cache to size MiB (valid values: 0-1024). Default: 4.

The cropping commands for each image are output using the format given by -f, or the default of ‘croptool_crop %wx%h+%l+%t '%f'’.

The following substitutions are performed:

%%
Print ‘%’.
%w
Print the width of the cropping rectangle in pixels.
%h
Print the height of the cropping rectangle in pixels.
%l
Print the location of the left side of the cropping rectangle in pixels.
%r
Print the location of the right side of the cropping rectangle in pixels.
%t
Print the location of the top side of the cropping rectangle in pixels.
%b
Print the location of the bottom side of the cropping rectangle in pixels.
%f
Print the filename of the image. Warning: This is printed as is, without any escaping.

If an unknown substitution is encountered, a warning is printed to standard error and the characters are printed verbatim.

Note that the coordinates are adjusted so they are entirely within the image, even if the original cropping rectangle was located partially outside. If the cropping rectangle was located entirely outside of the image, no command is printed for it.

ARROW LEFT
Go to the previous image.
ARROW RIGHT
Go to the next image.
RETURN
Go to the next image, copying the current cropping rectangle. Note that this copies the visual rectangle, not the scaled rectangle that is printed for the cropping command. In other words, when switching to an image that is a different size and thus scaled differently, the displayed rectangle will stay the same even though the pixels covered in the original image are different.
SHIFT + RETURN
Go to the previous image, copying the current cropping rectangle. The same caveat as above applies.
TAB
Switch the color of the cropping rectangle between the primary and secondary colors.
DELETE
Remove the cropping rectangle of the current image.
SPACE
Redraw the window. This is useful when automatic redrawing is disabled with -m.
q
Exit the program, printing the cropping command for any images with a cropping rectangle set. If the window is closed through some other means, no commands are printed.

LEFT-CLICK
When inside an existing cropping rectangle, drag it around. When on one of the edges, resize the rectangle, locking it to that axis. When on one of the corners, resize the rectangle regardless of axis. When outside an existing cropping rectangle, replace the current rectangle with a new one.

The croptool utility exits 0 on success, and >0 if an error occurs.

Normal usage:

$ croptool *.jpg > tmp.sh
$ sh tmp.sh

Or, if you're brave:

$ croptool *.jpg | sh

It is also possible to do more advanced things. For instance, to save cropped images into a separate directory instead of overwriting the original images, something like this can be done:

$ croptool -f "croptool_crop %wx%h+%l+%t '%f' '/path/to/cropped/%f'" *.jpg | sh

If more advanced features are needed for the actual cropping (e.g. a different output format), other tools such as convert(1) can be used:

$ croptool -f 'convert -crop %wx%h+%l+%t "%f" "$(basename "%f" .jpg).png"' *.jpg | sh

Note that no great care has been taken to deal with filenames containing single or double quotes. That is left as an exercise to the reader (hint: just don't have filenames containing quotes).

convert(1), croptool_crop(1), mogrify(1), selectool(1)

lumidify <nobody@lumidify.org>

The filenames are printed without any escaping, so filenames with quotes may cause issues depending on the output format.

Transparent portions of images should probably be shown differently, but I'm too lazy to fix that and don't really care at the moment.

Since the coordinates of the cropping rectangle are stored as integers, they will become skewed while resizing. If this becomes a real problem, though, you're probably doing something wrong anyways.

May 14, 2024