Reduces the size of photos and videos in a specified folder
Made with JavaScript
, NodeJS
ℹ️ About • ⚙️ Tools • 🔨 How to Build Project • 📁 File Structure
🖼 Screenshots • 📦 NPM Packages worth mentioning • 💡 Details • 🔗 Useful resources • 👤 Author
From time to time I need to empty the storage of my smartphone. For that purpose I move photos and videos to my computer. To optimize the storage of all those photos and videos I reduce their size.
Earlier the process was manual and relied on online services like Squoosh (didn't even optimize the size of videos because it was too cumbersome).
Then a sudden thought struck my mind: why not try to automate that process. It's not that difficult to do the process manually if there are only several photos. Although desire for optimization arises when there are hundreds of them.
Thus this is the goal of the project: to automate the size reduction of photos and videos!
I made it purely for myself... So as long as it works for me, it's perfectly fine.
- JavsScript
- NodeJS
Command | Description |
---|---|
npm i |
First things first, install all required packages |
node main name_of_the_directory |
Optimize the photos and videos inside of the specified folder. A new folder will be created. It will contain the optimized photos and videos |
node main |
Do the same what the previous command does, but this time the path to the folder will be taken from .env variable |
├── 📁 screenshots Screenshots
├── 📝 .env.example Example of an .env file (create your own .env !)
├── 📝 .gitignore Instructions for Git about what files to ignore
├── 📝 LICENSE MIT License. Basically you can do whatever you want with the code
├── 📝 main.js The heart, the soul, and the core of this project
├── 📝 package-lock.json Keeps track of the exact version of every package that is installed
├── 📝 package.json Various metadata relevant to the project, scripts, dependencies
└── 📝 README.md Project description
sharp |
Optimizes images |
fluent-ffmpeg |
Optimizes videos |
It took more time than expected. Starting to get used to that
Had to add a timer before accessing size of a newly created file. Otherwise NodeJS would return an error for some reason even though the attempt of accessing happened synchronously after the creation of the file... Had to increase that timer because otherwise NodeJS showed incorrect data for the reduces videos... Have no idea why that happened
Spent 1 hour in order to find out that you should use continue
instead of return
in for
loop... It is what it is, true and real.
The code is only about 130 lines of code, so I don't see any point in moving utility functions in a separate file.
The program optimizes only .jpg, .png, .jpeg, .mp4. It suffices all my needs. When necessary I might add more extensions.
n/a
- Telegram - @Arlagonix
- Github - @arlagonix