Yesterday, Facebook open-sourced Spectrum 1.0.0, a cross-platform image transcoding library for Android and iOS that makes uploading larger images easier. Spectrum has also improved the reliability and quality of image uploads across all Facebook apps. With Spectrum now open source, users can fully debug it and add support for new codecs using its plugin architecture.
Facebook uses Spectrum in-house across all of its mobile apps. It is an all in one package for performing image-manipulation tasks for lowering file-sizes and improving resizing, cropping, and transcoding.
Features of Spectrum 1.0.0
Spectrum uses Mozjpeg to achieve higher quality file size ratio. Spectrum makes image operations easier by cropping and rotating lossless. It focuses on increasing the quality for graphical content with operations like disabling chroma sampling.
Prevents common missteps
Since Spectrum’s API is declarative, it helps in preventing common missteps such as incomplete handling of EXIF metadata.
Written in C/C++
It is written in portable C/ C++ so users can adopt it to their environment. Java and Objective-C APIs are thin wrappers around the C++ core that makes development easier. C++ core allows higher execution speed for computational operations and provides control over allocations. This core allows sharing between apps on Android and iOS which makes outputs more consistent.
Automatic behavior definition using Recipes
Spectrum is unique because it does not require developers to manually, step-by-step define all behaviors. Instead, the developers just state what the desired outcome is, and the library takes it from there. Spectrum makes this possible by using ‘recipes’, that are bundled with the plugins used by the library and sorted by Facebook. Recipes help developers in choosing the optimal execution sequence for individual requests. For example, the JPEG plugin will provide recipes for the lossless cropping and rotation of JPEG images.
Integration with Mozilla JPEG
Integration with MozJpeg, a native library, helps Spectrum to control encoding parameters beyond the general purpose platform APIs. It helps developers to utilize intensive encoding, which requires more time for processing but significantly reduces the file size.
Other minor features
- Spectrum 1.0.0 can write interlaced PNG files.
- This release supports consuming JPEG images with 4:1:1 and 4:4:0 chroma subsampling.
- For iOS bitmaps, Spectrum 1.0.0 will default to 4:2:0 chroma subsampling.
- This release is built with proper SIMD support for mozjpeg on Android ARMv7.
- It optimizes the interplay between pixel-perfect resizing and decoder sampling.
Hacker news users are excited about this news and are relieved that they don’t have to recreate a bunch of scaffolding around image encoders. Users are also comparing this library with other apps like ImageOptim, a free Mac app that can handle JPEG, GIF and PNG and Google’s Guetlzi that can reach 20-40% compression without any loss of quality.
All is not bright, however. Users have also expressed concerns with using Spectrum saying that Facebook provides the worst image compression. One user commented on HackerNews, “Facebook photos are compressed to a point where they look horrible. Why would anyone want to use this? I do not see what this benefits any developer over just using mozjpeg with better settings.”
Some users are unhappy with Messenger videos too. Another user commented, “If any Facebook compression engineer reads this, please fix the sound in Messenger videos! The sound bitrate is absolutely terrible, only for ridiculous bandwidth savings.”
Also, there are issues with the name as there are other products with the same name. A comment reads, “I like how there are 2 products called Spectrum on the front page and they are completely unrelated. Anyway, this lib looks pretty ok for its purpose.” Another comment reads, “There’s also the article that wants to sell you a spectrum analyzer to search your hotel room for bugs.”