whoisjoe.com

Optimizing Images

 and learning node.js 

July 19, 2018

Home About Projects Blog LinkedIn ReThink Security

I started down a little bit of a rabbit hole when I wanted to optimize and scale the images on my site. As you can see there are a lot rather large images on my site, which I like the look of. I just don’t like that some of them were greater than 5MB each!

I started out by searching for a basic bulk image processing tool. I wanted something that wasn’t bloated, janky, or broken. It turns out that wasn’t easy for me to find. Instead I found a few node modules that would do what I wanted. First I started using imagemin-mozjpeg - npm, which is great for the optimization piece, and great for jpegs, but I also want to optimize pngs and resize my files. That got me looking further. I ended up settling on sharp, a library that can do all the processing I wanted.

After a bit more poking around I decided to write my own script. It started out very basic, but like most things it began to develop into something slightly more useful and more complicated than when I started.

What I came up with is a command line node.js tool that will optimize and scale png and jpg files and copy other files to the destination directory if requested. This was nice for me, because I just dump all my images and things into my uploads directory so there are some MP3s and PDFs in there as well.

Before processing the images on my site added up to a whopping 38.8MB, I’ve cut it down to less than 25% to 9.1MB.

All in all it was a pretty fun and painless experience. Having never written node before (and little Javascript) there were some bumps, but node’s developers have done a good job of documenting things along the way.

If this is useful to you, please check out the code (and improve it ) on my gist here: A command line image optimizer written in node. · GitHub

Here are some of the resources I used:

  • Building command line tools with Node.js - Atlassian Developers
  • File System | Node.js v10.7.0 Documentation
  • sharp
  • commander - npm
  • chalk - npm
  • Beautiful Free Images & Pictures | Unsplash (where I get many of the pretty images on the site)
  • 81 More Posts
  • So, You're a Manager Now
  • A Mixtape in 2022
  • The Middle Path of Planning and Reflection
  • Micromanagement and Trust
  • On Giving Advice
  • Emergency Preparedness During Coronavirus Frenzy
  • Mind Map Your Life
  • Start With the Hard Part
  • Delight in the Details
  • Introducing ReThink Security
  • Newsletter & Recommendations
  • Take a Moment
  • Triage Decision Making
  • Show Your Work
  • Getting Back Up
  • Max Out vs. Continuous Development
  • Mental Diet and Exercise
  • Asking for Help Part 2 - Alerting
  • High Water Mark
  • Who Do You Want to Be
  • Presentation Tips
  • Asking for Help
  • China Hijacking the Internet
  • Recording Audio with AirPods in Imovie
  • Active Decisions
  • Create/Publish Scripts
  • Specialize or Do Not Specialize
  • Exactis Breach
  • Optimizing Images
  • What I Track
  • What I’m Thinking About May
  • What I’m Thinking About March
  • What I’m Thinking About January
  • Building a Collaborative & Social Application Security Program
  • Lazy Days in the Cloud
  • Delegate Then Do
  • So you want to be a better programmer
  • Project Success
  • Don't Short Circuit a Lesson
  • Scale Your Solution to the Problem
  • Digital Currencies
  • Fortnightly
  • Why You Should Have Trust Issues with Pokemon Go, and Every Other App on Your Phone
  • In Defense of Reverse Engineering and Responsible Disclosure
  • Ruby open allows command injection if user controlled
  • New Mac Install Guide
  • Understanding Customer Needs and Helping Them Mature
  • My Experiences with IOS8 and Yosemite so far
  • The Importance of Vulnerability Disclosure Programs and Bug Bounties
  • My New Record Player and Beck - Morning Phase (The Vinyl Experience)
  • An Hour of Code with Code.org
  • Gmail Changes to Displays Images by Default
  • Why I Donated to Help Jailbreak iOS7 & You Should Too
  • Email Strategy
  • Shutdown
  • Anatomy of a Distributed Denial of Service (DDoS) Attack
  • NASA Forced to Suspend All Public Outreach & Education Programs
  • Joe_CMS Open Source!
  • Mobile Application Security Testing FAQs: Post #1
  • How Much Security Does Obfuscation Get You?
  • Why Privacy Matters Even if You Have 'Nothing to Hide'
  • What LinkedIn Should Have Done with Your Passwords
  • Constant Vigilance
  • Boeing Paying Hackers to Break into Their Systems
  • My Reading Cycle
  • Developing Tools for Professional Hackers
  • Finding Your Inner Evildoer (4/4): An Evil Streak
  • Finding Your Inner Evildoer (3/4): A Good Imagination
  • When to Rebuild Your Process from Scratch
  • Finding Your Inner Evildoer (2/4): Complete Knowledge of the System
  • Continuous Incremental, Personal Improvement
  • Finding Your Inner Evildoer: Part 1
  • CISCO Password Revealer
  • Battling with Word and Excel
  • Which is More Secure: Windows or Linux?
  • The High Cost of an Application Security Data Breach
  • Using the ConfigurationManager to Access your ConnecitonStrings in the Web.Config
  • New WikiRater Features
  • When is it OK to Build up Technical Debt
  • Time Management with the Pomodoro Technique
  • Manage Energy Not Time
  • Goals, Results and Activities - defining your productivity
© 2022 whoisjoe.com