Implementing One-Click GIF Compression with Alfred
Personal blogs often need some recorded GIF animations. Considering that GIF size affects page loading experience, I need to manually compress GIFs. The compression process is tedious and time-consuming, so I decided to write a small tool to improve operational efficiency.
Effect
Select file, invoke Alfred, type gif
, select Compress GIF, press Enter.
Workflow download link: Click here
Notes
Current workflow supports scale/colors personalized parameter settings
- scale
- Ratio, e.g., 0.5 means width and height are reduced to 0.5 times the original
- colors
- Palette length, value between 2-256. Smaller numbers mean higher compression but greater quality loss
Implementation Details
Let’s talk about the key parts of the tool implementation. For complete source code, check the workflow directly.
- Gifsicle is an open-source tool that can perform personalized GIF compression, such as scale ratio and color adjustment, achieving size compression
- AppleScript to get the complete path of currently selected files
Final Thoughts
From now on, GIF compression only requires selecting files and invoking the compression command. No more visiting third-party tool websites to upload, download, and compress. Efficiency is significantly improved.