sic 0.10.1

Accessible image processing and conversion from the terminal (and a front-end for the 'image' crate).
Documentation

Build Status

sic image cli

Enables you to perform operations on images and convert images to a variety of image formats. 'sic' or 'sic image cli' is a (partial) image crate cli front-end.

The image conversion and operations are performed by the awesome image crate :balloon:. It was initially created to try out another awesome Rust library: clap :tada:.

Install

Install with cargo: cargo install sic Update with cargo: cargo install --force sic

Pre build binary: see releases.

From the source:

  • Setup rust and cargo with (for example) rustup Rust version >= 1.31 with 'Rust edition 2018' is required.
  • Clone this repo: git clone https://github.com/foresterre/sic.git
  • Switch to this repo: cd sic
  • Build a release: cargo build --release

Usage

Convert an image from one format to another, for example from PNG to JPG.

  • Command: sic --input <input> --output <output>
  • Shorthand: sic -i <input> -o <output>
  • Example: sic -i input.png -o output.jpg

Previously sic <input> <output> was used to specify the input and output image files. This method of specifying input and output image paths is still supported, if and only if no other input and output option ( such as '--input' and '--output') is used. Using the '--input' and '--output' arguments is however the preferred way to specify input and output image file paths.

Covert an image from one format to another while not caring about the output file extension.

  • In general sic --output-format "<format>" -i <input> -o <output> (or sic -f "<format>" -i <input> -o <output>)
  • Example sic --output-format png -i input.bmp -o output.jpg (Note: output.jpg will have the PNG format even though the extension is jpg.)

Supported image output formats are (as of 0.8.0): bmp, gif, ico, jpg (or jpeg), png, pbm, pgm, ppm and pam. The JPEG quality can optionally be set with --jpeg-encoding-quality <value> (value should be an integer from 1 up to (including) 100). Default value if not user overridden is 80. The PNM format (specifically PBM, PGM and PPM) use binary encoding (PNM P4, P5 and P6 respectively) by default. To use ascii encoding, provide the following flag: --pnm-encoding-ascii.

Apply image operations to an image. As of release 0.10.0, there are two methods to apply image operations on an image. The first method is by using the --apply-operations "<operations>" (shorthand: -x or -A) cli argument and providing statements which tell sic what operations should be applied on the image, for example: sic -i input.jpg -o output.jpg --apply-operations "fliph; blur 10; resize 250 250" When more than one image operation is provided, the separator ; should be used to separate each operation statement. Any version of the program prior to 0.10.0 is limited to this method of applying image operations.

From release 0.10.0 forward, there is a second method which can be used. This method uses cli arguments to inform sic, what image operations should be applied in what order. Do note that the order in which these arguments are provided does (not in every case though =D) matter.

If we use the image operations as cli arguments method the previously shown example becomes: sic -i input.png -o output.jpg --flip-horizontal --blur 10 --resize 250 250 Note that image operation cli arguments can not be combined with --apply-operations.

The image operations are applied left-to-right for both methods. Additionally the methods can not be used both at the same time. Either the --apply-operations method or the image operations as cli arguments method should be used.

The available image operations are:

operations syntax* available (from version) description
blur blur <fp> Yes (0.5.0) Performs a Gaussian blur on the image (more info). An argument below 0.0, will use 1.0 instead.
brighten brighten <int> Yes (0.7.0)
contrast contrast <fp> Yes (0.7.0)
crop crop <int> <int> <int> <int> Yes (0.9.0) Syntax: crop <lx> <ly> <rx> <ry>, where lx is top left corner x pixel coordinate starting at 0, ly is the top left corner y pixel coordinate starting at 0, rx is the bottom right corner x pixel coordinate and ry is the bottom right corner y pixel coordinate. rx and ry should be larger than lx and ly respectively.
filter3x3 filter3x3 <args9> Yes (0.7.0)
flip horizontal fliph Yes (0.5.0) Flips the image on the horizontal axis.
flip vertical flipv Yes (0.5.0) Flips the image on the vertical axis.
gray scale grayscale Yes (0.7.0)
hue rotate huerotate <int> Yes (0.7.0) Rotate's the hue, argument is in degrees. Rotates <int>%360 degrees.
invert invert Yes (0.7.0)
resize resize <uint> <uint> Yes (0.5.0) Resize the image to x by y pixels. Can both up- and downscale. Uses a gaussian sampling filter if no override value is set.
> set resize preserve_aspect_ratio Yes (0.9.0) Enables preservation of the aspect ratio when resizing.
> set resize sampling_filter <value> Yes (0.9.0) When resizing use the <value> sampling filter. Choices are catmullrom, gaussian,lanczos3,nearest,triangle.
rotate90 rotate90 Yes (0.7.0)
rotate180 rotate180 Yes (0.7.0)
rotate270 rotate270 Yes (0.7.0)
unsharpen unsharpen <fp> <int> Yes (0.7.0)

* The exact syntax applies to the --apply-operations method, but can also be used as a reference for the image operations as cli arguments method.

For some operations, their behaviour can be (slightly) changed by setting an operation modifier. These modifiers can be overwritten and they can also be reset (to their default behaviour).

environment operation syntax available (from version) description
set environment option set <operation> <option-of-operation> [<args 0..n>] Yes (0.9.0) Enables the use of a modifier for an operation. Any operation which uses the value of the modifier will use the set modifier value instead of the default value. Can be overwritten by calling set again for the same operation and modifier specifier.
unset environment option del <operation> <option-of-operation> Yes (0.9.0) Resets the modifier value. Any operation which looks at the value of this modifier will use the default value instead.

legend:

<uint> means any 32 bit unsigned integer is required as argument.
<int> means any 32 bit signed integer is required as argument.
<fp> means any 32 bit floating point number is required as argument.
<value> means a pre defined value. 
<args9> means `<fp> <fp> <fp> <fp> <fp> <fp> <fp> <fp> <fp>`.

Image operation example usage:

blur example: sic -i in.png -o out.png --apply-operations "blur 1.3;" or sic -i in.png -o out.png --blur 1.3

brighten example: sic -i in.png -o out.png --apply-operations "brighten 2;" or sic -i in.png -o out.png --brighten 2

contrast example: sic -i in.png -o out.png --apply-operations "contrast 0.7;" or sic -i in.png -o out.png --contrast 0.7

crop example: sic -i in.png -o out.png --apply-operations "crop 0 0 10 10;" or sic -i in.png -o out.png --crop 0 0 10 10

filter3x3 example: sic -i in.png -o out.png --apply-operations "filter3x3 1.0 1.0 1.0 0 0 0 0.5 0.5 0.5" or sic -i in.png -o out.png --filter3x3 1.0 1.0 1.0 0 0 0 0.5 0.5 0.5

flip horizontal example: sic -i in.png -o out.png --apply-operations "fliph" or sic -i in.png -o out.png --flip-horizontal

flip vertical example: sic -i in.png -o out.png --apply-operations "flipv" or sic -i in.png -o out.png --flip-vertical

gray scale example: sic -i in.png -o out.png --apply-operations "grayscale" or sic -i in.png -o out.png --grayscale

hue rotate example: sic -i in.png -o out.png --apply-operations "huerotate -90" or sic -i in.png -o out.png --hue-rotate -90

invert example: sic -i in.png -o out.png --apply-operations "invert" or sic -i in.png -o out.png --invert

resize example: sic -i in.png -o out.png --apply-operations "resize 100 100" or sic -i in.png -o out.png --resize 100 100

resize with preserve aspect ratio example: sic -i in.png -o out.png --apply-operations "set resize preserve_aspect_ratio; resize 100 100" or sic -i in.png -o out.png --set-resize-preserve-aspect-ratio true --resize 100 100

resize with custom sampling filter (default is 'gaussian') example: sic -i in.png -o out.png --apply-operations "set resize sampling_filter triangle; resize 100 100" or sic -i in.png -o out.png --set-resize-sampling-filter triangle --resize 100 100

rotate 90 degree example: sic -i in.png -o out.png --apply-operations "rotate90" or sic -i in.png -o out.png --rotate90

rotate 180 degree example: sic -i in.png -o out.png --apply-operations "rotate180" or sic -i in.png -o out.png --rotate180

rotate 270 degree example: sic -i in.png -o out.png --apply-operations "rotate270" or sic -i in.png -o out.png --rotate270

unsharpen example: sic -i in.png -o out.png --apply-operations "unsharpen -0.7 1" or sic -i in.png -o out.png --unsharpen -0.7 1

example with multiple image operations which are applied from left-to-right: sic -i in.png -o out.png --apply-operations "rotate180; fliph; set resize sampling_filter nearest; resize 75 80; huerotate 75" or sic -i in.png -o out.png --rotate180 --flip-horizontal --set-resize-sampling-filter nearest --resize 75 80 --hue-rotate 75

Other resources on image operations

For additional information on available options and flags, run sic --help.

Suggestions, Questions, Bugs

Feel free to open an issue :mailbox_with_mail: if you have a suggestion, a question or found a bug =).

:guitar: :trumpet: :violin: :saxophone: