It helps you interlace an image or multiple images for web-page usage.
This program links against ImageMagick 7.1.1-31 or later built with HDRI enabled, so the library and its development headers have to be installed before building. Distribution packages are often ImageMagick 6, or are built without HDRI, in which case building from source is the reliable route.
sudo apt install liblcms2-dev libwebp-dev
wget https://download.imagemagick.org/archive/ImageMagick.tar.gz
tar xf ImageMagick.tar.gz
cd ImageMagick-*
./configure --enable-hdri
make -j$(nproc)
sudo make install
sudo ldconfigbrew install imagemagickOnce ImageMagick is in place,
cargo install image-interlacerThe CI workflow is a working reference for both platforms, and the Makefile builds a statically linked musl binary. Set MAGICK_PATH to your ImageMagick build directory and MUSL_PATH to your musl toolchain directory before using the Makefile.
An image is decoded, switched to an interlaced scheme and encoded again. PNG and GIF use lossless encoding, while JPEG does not: the result is re-compressed rather than rearranged in place, so it loses a little quality. That happens only once, because the result is interlaced with its orientation applied and is skipped when this program runs on it again. The JPEG is re-compressed with the quality and the subsampling ImageMagick reads from the original, so nothing beyond that round trip is thrown away.
An animated PNG (APNG) is skipped and left alone, because APNG output is not supported and writing a plain PNG would throw the animation away.
Unless --remain-metadata is given, the metadata is removed. Either way, the rotation or mirror an image asks for in its metadata is applied to the image pixels, so the stored width and height match the displayed dimensions. When metadata is kept, its orientation is reset to prevent a viewer from rotating the image again.
Images with an embedded ICC color profile are converted to sRGB before that profile is removed. This requires the ImageMagick lcms delegate and can change pixel values, especially for colors outside the sRGB range. --remain-metadata keeps the profile and its original colors.
A single file is checked by its contents. Directory mode first selects JPEG, PNG and, with --allow-gif, GIF file extensions, ignoring case, then checks the selected files by their contents.
Images which are already interlaced and need no orientation correction are left as they are, metadata included. With -o, they are copied to the output unchanged. An already interlaced image which needs a rotation or mirror is encoded again to apply its orientation.
An output directory inside the input directory is excluded from the scan, including its existing files. An output directory which is a parent of the input directory is rejected. Using the same directory for both still allows in-place processing.
--single-thread processes one image at a time. ImageMagick can still use several threads inside each image operation.
Multi-frame GIF images are encoded through a temporary file, so the system temporary directory has to be writable.
EXAMPLES:
image-interlacer /path/to/image # Check /path/to/image and make it interlaced
image-interlacer /path/to/folder # Check /path/to/folder and make images inside it interlaced
image-interlacer /path/to/image -o /path/to/image2 # Check /path/to/image and make it interlaced, and save it to /path/to/image2
image-interlacer /path/to/folder -o /path/to/folder2 # Check /path/to/folder and make images inside it interlaced, and save them to /path/to/folder2
image-interlacer /path/to/folder -o /path/to/folder2 -f # Check /path/to/folder and make images inside it interlaced, and save them to /path/to/folder2 without overwriting checks
image-interlacer /path/to/folder --allow-gif -r # Check /path/to/folder and make images inside it including GIF images interlaced and also remain their metadata
Usage: image-interlacer [OPTIONS] <INPUT_PATH>
Arguments:
<INPUT_PATH> Assign an image or a directory for image interlacing. It should be a path of a file or a directory
Options:
-o, --output-path <OUTPUT_PATH> Assign a destination of your generated files. It should be a path of a directory or a file depending on your input path [alias: --output]
-s, --single-thread Process one image at a time; ImageMagick may use multiple threads
-f, --force Force to overwrite files
--allow-gif Allow to do GIF interlacing
-r, --remain-metadata Remain the metadata of all images [alias: --remain-profile]
-h, --help Print help
-V, --version Print version