This script standardizes the size of images, particularly brand logos, across various formats, aspect ratios, and sizes. It resizes the source image to the desired dimensions and centers it within a larger frame of the specified size, filling the background with the chosen color.
- Process images with different formats (JPG, JPEG, PNG, SVG, WEBP).
- Batch processing for directories of images.
- Resize and trim images with customizable parameters.
- Set background color and extend images to specified dimensions.
-i, --input <file_or_directory>
: Input file or directory. Required.-o, --output <directory>
: Output directory. Required.--fuzz <percentage>
: Fuzz percentage for trimming the image. Useful when work with some low quality JPEGs. Default is0
.--width <width>
: Output image width. Default is400
.--height <height>
: output image height. Default is230
.--tolerance <tolerance>
: Height tolerance for scaling. Default is0
.--logo-width <width>
: Width of the logo. Default is230
.--logo-height <height>
: Height of the logo. Default is85
.--background <color>
: Background color to use. Default iswhite
.--workdir <directory>
: Temporary working directory. Default is a temporary directory created by the script.--batch
: Enable batch processing mode for directories.-q, --quiet
: Suppress log messages.
To protect aspect ratio, two strategies used for expanding logo:
If (desired logo width / original logo width) * original logo height smaller than desired logo height + tolerance (in px), logo will resized to desired height, otherwise logo will resized to desired width.
You can run stdlogo.sh
directly from the command line with various options.
To process a single image:
bash stdlogo.sh -i input_image.png -o output_directory --fuzz 10 --width 400 --height 230 --tolerance 10 --logo-width 230 --logo-height 85 --background white
To process all images in a directory:
bash stdlogo.sh -i input_directory -o output_directory --batch --fuzz 10 --width 400 --height 230 --tolerance 10 --logo-width 230 --logo-height 85 --background white
- ImageMagick: Required for image processing tasks.
- awk: Required for mathematical calculations.
- mktemp: Required for creating temproary directories.
You can see the demo here.
- The script does not remove background colors. For logos with solid backgrounds, use background removal services like remove.bg.
- High values for
--fuzz
may cause distortions in logos. - Some logos with solid backround may be over-trimmed.
The original script was written in March 2021.
This script is provided under the MIT License. See the LICENSE file for more details.