Home > Web Front-end > JS Tutorial > I Created a Photo Compressor CLI Tool

I Created a Photo Compressor CLI Tool

Mary-Kate Olsen
Release: 2025-01-15 20:30:43
Original
432 people have browsed it

Hey there! Have you ever struggled with optimizing images for your website or project, I’ve got something exciting: photo-compressor. It’s a command-line tool designed to compress and convert images to the super-light .webp format seamlessly.

I Created a Photo Compressor CLI Tool

This tool is powered by Sharp, which makes it fast and reliable. It helps you optimize media like a pro. Whether you’re working with local files or cloud-hosted images, photo-compressor has your back.

Why Use photo-compressor?

Here’s why you’ll love it:

  • Optimize Local Images: Compress images in a local directory effortlessly.

  • Optimize Cloud Images: Process images directly from URLs or even a directory of image URLs.

  • No Naming Headaches: It’ll automatically handle file name conflicts for you.

  • Detailed Logs: Get insights on savings and processing time.

Installation: Get Started in No Time

Installing photo-compressor is a breeze. Choose your favourite package manager:

npm install -g photo-compressor
Copy after login
Copy after login

Or, if you’re a Yarn fan:

yarn global add photo-compressor
Copy after login
Copy after login

Don’t want to install anything globally? No problem! Run it directly using npx:

npx photo-compressor
Copy after login

How to Use It: Commands and Options

Using photo-compressor is straightforward. Here’s the rundown of its commands and options.

Common Options

  • -h, --help: Display help information.

  • -V, --version: Check the current version of the package.

Commands

1. Optimize Local Images

Easily compress images from a local directory:

photo-compressor local --dir <path_to_directory> --output <path_to_output_directory>
Copy after login

Options:

  • -d, --dir : Directory to scan for images (required).

  • -o, --output : Output directory for optimized images (default: ./optimized).

2. Optimize Cloud Images

Do you have images hosted online? Compress them like this:

photo-compressor cloud --url <image_url_OR_array_of_images> --output <path_to_output_directory>
Copy after login

Options:

  • -u, --url : URL of the image or an array of image URLs (required).

  • -o, --output : Output directory for optimized images (default: ./optimized).

Real-World Examples

Here are some practical examples to get you started:

Optimize Local Images

npm install -g photo-compressor
Copy after login
Copy after login

Optimize Cloud Images

yarn global add photo-compressor
Copy after login
Copy after login

A Quick Backstory

Why did I create this tool? Honestly, I was binge-watching Silicon Valley and got inspired to build something related to compression. It turns out, it’s a neat solution for web developers who need to quickly optimize images for better web performance. (P.S. I’m still a noob, so feedback is always welcome!)

Join the Fun

The development community is all about collaboration. If you’ve got ideas to improve this tool or find any bugs, head over to our GitHub repository and contribute!

Happy Coding! Let me know in the comments what you think about the package.

The above is the detailed content of I Created a Photo Compressor CLI Tool. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template