Overview
    • PDF

    Overview

    • PDF

    Article summary

    Image Resizer is a command-line application built with .NET designed to resize images. It allows you to resize a provided image by specifying a target size in bytes and an output folder.

    The tool aims to maintain the original image's likeness. Any differences should stay within the tolerances of human vision.

    The output of this tool is targeting a value of 90% or above visuality similarity score in comparison tests using a cross correlation algorithm.

    Import / Export Integration

    Supported files can be processed using the export function of the Glasswall Engine. This function outputs a ZIP file containing all images extracted from the original document.

    This feature allows for custom processing of the images, which can then be reinserted into the original document using the import function.

    However, there are some integration limitations to be aware of:

    • Changing the file names of images to anything different from the original names will result in a failure to place the images back into the document during the import process.
    • File names are case sensitive.
    • If the file size of an image exceeds the original size, the import may not be successful.

    The tool enables users to resize images to a target size that is less than or equal to the original file size, ensuring a smooth import process.

    Usage

    Glasswall.ImageResizer.CmdLine [options]

    Options

      -i, --in <filename> (REQUIRED)                    Input file name
      -o, --out <filename> (REQUIRED)                   Output file name
      -t, --target <max size in bytes> (REQUIRED)       Target maximum output file size
      -l, --memory-limit <max memory limit percentage>  An optional number that specifies the maximum amount of system
                                                        memory percent the image resize is limited too. [default: 50]
      -?, -h, --help                                    Show help and usage information
    

    Exit Codes

    Exit CodeDescription
    0Successfully resized or the file was already the target size
    1The input file target size is less than zero
    2The input file could not be found
    3The input file could not be loaded as it is corrupt or unsupported
    4The input file could not be loaded for an unknown reason
    5Part of the output path does not exist
    6Could not write the output file for an unknown reason
    7General error in the magick library when trying to resize
    8Could not reach the desired target size
    9Unexpected error
    10Memory limit option was not between 0-100

    Temporary directory

    In order to ensure the successful resizing of files, during processing the image resizer tool may use a temporary directory located at "$TMPDIR/.gw-image-resizer" or "/tmp/.gw.image-resizer".

    Limiting Memory

    By default the memory allocation used for resizing images is limited to 50% of system memory. This can be overriden to a value between 1-100 with the optional command line option "-l".

    Support

    The tool currently supports the following:

    • JPEG
    • PNG
    • BMP
    • TIFF (see GeoTiff known issue)
    • GIF

    Other files supported by ImageMagick may load correctly but have not explicitly been implemented.

    Resizing Strategy

    All supported image files go through a set of methods to reach the target size. For example:

    Compression Quality:

    JPEG / JPG files have quality set to 25.

    PNG files are set to 100.

    Other file types remain unchanged, however the compression method is always set to LZW.

    GIF Optimization

    Since GIFs can be comprised of multiple images and layers, there are potential optimizations to be made in order to reduce file size.

    If the different layers of an image are of different sizes, Optimization is done by Image Magick to reduce the file size.

    Otherwise the GIF is Coalesced, which merges similarities in images in the sequence to reduce size.

    Transparency is also optimized at this point, replacing duplicate pixels data across the sequence with transparency.

    Quantize

    All images will then be Quantized, which will cap the number of colors to 128, not changing the value if less than this already.

    Downscaling

    If the target is not yet reached, the image will then be resized until it is. Resolution is reduced to 95% of the original continuously until the target is reached or it cannot reduce the resolution any further.

    Known issues

    Processing can remove locational data from the pixels in GeoTIFF. In addition, regular TIFF's may have colors flipping in grayscale images.

    Third Party Libaries

    Libary NameLibary VersionTypeLicense TypeLicense UrlProject UrlSource Url
    System.CommandLine2.0.0-beta4.22272.1LibaryMITLinkLinkLink
    System.CommandLine.Hosting0.4.0-alpha.22272.1LibaryMITLinkLinkLink
    Magick.NET-Q8-AnyCPU13.10.0LibaryApache-2.0LinkLinkLink

    Glasswall's Image Resizer tool utilizes the "Magick.NET-Q8-AnyCPU" NuGet package which is a dotnet wrapper for ImageMagick.

    ImageMagick itself is a free open source tool that is used for editing and manipulating digital images.


    Was this article helpful?

    What's Next