comp-img
v1.3.0
Published
A command-line tool for compressing large quantities of images. Also has the ability to quickly compress a single image. This tool removes the dependency on other similar tools like TinyPNG to accomplish these tasks and is free.
Maintainers
Readme
img-compressor (comp)
A command-line tool for compressing large quantities of images. Also has the ability to quickly compress a single image. This tool removes the dependency on other similar tools like TinyPNG to accomplish these tasks and is free. Uses the jpegoptim and pngquant open-source image compression libraries.
Installation
npm i jpegoptim-bin
npm i pngquant-bin
npm i -g comp-img
Usage
Compressing large quantities of images
- "cd" into the project's directory
cd ~/Desktop/example-project
- Run comp
- Example usage:
comp startcomp start -i "imgs"comp start -i "imgs" -o "comp-imgs"comp start --input "imgs"comp start --input "imgs" --output "comp-imgs"comp start -e "folder1 folder2/sub2" -vcomp start --except "folder1 folder2/sub2" --verbose
- The
-ior--inputoption allows you to specify where the uncompressed images can be found- By default the tool assumes your input directory is
./img. If this is not the case use the following command:comp start -i "imgs"comp start --input "imgs"
- By default the tool assumes your input directory is
- The
-oor--outputoption allows you to specify where the compressed images should be found- By default the tool will put the compressed images in
./comp. If you would like the images placed elsewhere, use the following commandcomp start -o "comp-imgs"comp start --output "comps"
- By default the tool will put the compressed images in
- This tool has the ability to exclude a directory of images (and all of the subdirectories inside the excluded directories) from compression completely. This option might be useful if you have a specific folder or folders inside your input directory that are very large will slow down processing/compression time considerably if not excluded
- Folder paths can either be relative or absolute, but preferably relative. Separate multiple folder names with a space or comma
comp start -e "folder1 folder2/sub3"comp start -e "folder1,folder2/sub3"comp start --except "folder1 folder2/sub3"comp start --except "folder1,folder2/sub3"
- During compression the
-vor--verboseoptions give you the ability to see the file path of every file logged to the terminal before it is compressed. Since this tool was designed to compress a large number of images at once, this could quite a lot of output, so this option is disabled by default.comp start- Only output the file path of files that are not
.jpg,.jpegor.pngimages
- Only output the file path of files that are not
comp start -vorcomp start --verbose- Will output the file path both the skipped non-image files (i.e. the files that don't end in
.jpg,.jpegor.png) as well as the file path of each image before it is compressed.
- Will output the file path both the skipped non-image files (i.e. the files that don't end in
- Useful for debugging purposes to see exactly what images the tool compressed.
- All options can be chained together
comp start --input "imgs" --output "comp-imgs"comp start -i "imgs" -o "comp-imgs"comp start -i "uncomp" -o "imgs" -e "folder1 folder2/sub2"comp start -e "folder1 folder2/sub2" -vcomp start --except "folder1 folder2/sub2" --verbose
- Example usage:
Quickly compress a single image
- "cd" into the directory that has the image you want to compress
cd ~/Desktop
- Run comp on that single image
comp example-image.pngcomp folder one/img.jpegcomp ~/Desktop/the-folder/image.jpg
Known issues
- When compressing images smaller than 1 KB the compressed image is slightly larger in file size than the original image
- When running
comp startinitially, an error is thrown for the .jpgs and .jpegs in the root directory and the images are not compressed, after runningcomp starta second time, no error is thrown and the .jpgs and .jpegs in root directory are compressed like they should be (doesn't happen all the time)- If this occurs re-run
comp startwith the same options as you had before, this usually fixes this issue. - This issue doesn't occur ever time
- If this occurs re-run
- Folder names with spaces in them sometimes unexpectedly cause errors to occur during compression
Feature wish list for future versions
- More descriptive output when actual compression is taking place that states how much file size was saved by compressing the image
- Perhaps a progress bar for when compressing large quantities of images
- Add ability to customize compression level (from 0 - 100) for images (currently 85)
