dev-resources.site
for different kinds of informations.
How “Silicon Valley” Inspired Me to Create a Photo Compressor CLI for Web Developers
Hey there! So I was binging the famous HBO TV series Silicon Valley and got inspired to build something related to compression. And here's a thought – have you ever struggled with optimizing images for your website or project? If so, After hacking around for half a day 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.
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. I understand it's just a wrapper around sharp but we will be adding features and further optimization down the line
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
Or, if you’re a Yarn fan:
yarn global add photo-compressor
Don’t want to install anything globally? No problem! Run it directly using npx:
npx photo-compressor
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>
Options:
-d, --dir <path>
: Directory to scan for images (required).-o, --output <path>
: 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>
Options:
-u, --url <url>
: URL of the image or an array of image URLs (required).-o, --output <path>
: Output directory for optimized images (default:./optimized
).
Real-World Examples
Here are some practical examples to get you started:
Optimize Local Images
photo-compressor local --dir ./images --output ./optimized
Optimize Cloud Images
photo-compressor cloud --url ['https://example.com/image1.jpg', 'https://example.com/image2.jpg'] --output ./optimized
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.
Featured ones: