Sharpei
Sharpei is a command line tool for an easy image resizing and creating thumbnails
built on top of the vips library.
Key features:
- focuses on image quality
- aware of gamma correction
- aware of color profiles
- aware of grayscale images
- designed for batch processing
- supports multiple profiles
Installation
Vips library must be installed first. On the macOS you can install it via the homebrew:
brew install vips
On the Debian or Ubuntu you can install it via the apt:
sudo apt install libvips libvips-dev
For instructions for other platforms please visit
the vips homepage.
After that you can install the sharpei:
CGO_CFLAGS_ALLOW="-Xpreprocessor" go install github.com/meownoid/sharpei@v1.10.0
Usage
For simple usage specify only one parameter width
.
Image will be scaled proportionally to the specified width.
sharpei -width 1024 image.jpg
This command will create image-thumbnail.jpg
in the same directory.
For vertical images you can also specify height. Maximal dimension will be used.
Horizontal images will be scaled to the specified width and vertical images
will be scaled to the specified height.
sharpei -width 1024 -height 512 image.jpg
Following command will process all images in the directories source-1
and source-2
,
results will be written to the directory processed
preserving original file structure:
sharpei \
-width 1024 \
-height 512 \
-output processed \
source-1 source-2
You can also specify output color profile.
sharpei \
-width 1024 \
-height 512 \
-color-profile /System/Library/ColorSync/Profiles/AdobeRGB1998.icc \
image.jpeg
Sharpei includes 3 color profiles appropriate for free distribution: srgb-v2
(srgb
), srgb-v4
, gray
.
Command line arguments
-
-config
– path to the config
-
-output
– output directory
-
-format
– format of the output file name (default: {name}-{profile}
)
-
-profile
– profile name (default: thumbnail
)
-
-rewrite
– use it to rewrite existing files
-
-width
– image width
-
-height
– image height
-
-color-profile
– output color profile (name or path), special value same
means same as input
-
-file-type
– output image file type, special value same
means same as input
-
-verbose
– output debug information from each stage of the image processing
Although sharpei can process individual files, it is designed to batch process images within a complex directory structure.
For that, you need a configuration file.
Configuration file
You can create a configuration file in the working directory (sharpei.yml
or .sharpei.yml
)
or in the home directory (~/.sharpei.yml
).
With the configuration file, you can define several profiles, specify the output file type and image quality for each profile.
Example configuration
output: 'processed'
format: '{name}-{profile}'
rewrite: true
copy_original: true
profiles:
x1:
width: 1000
file_type: 'jpg'
quality: 90
x2:
width: 2000
file_type: 'jpg'
quality: 90
x3:
width: 3000
file_type: 'jpg'
quality: 90
small:
width: 100
height: 100
file_type: 'png'
compression: 5
Then you can run sharpei:
sharpei -config path/to/config.yml source-1 source-2 source-3