The quality of images captured by smartphones keeps improving at a rapid pace, as does the size of those images, often making them difficult to load. However, a solution open-sourced by Facebook this week will help developers and engineers tackle those issues.
Facebook developed Spectrum, an image-processing library for iOS and Android that enabled the social network to boost the reliability and quality of image uploads at a large scale across its family of applications.
Spectrum 1.0.0 was officially released to GitHub Thursday, with the aim of helping developers bring similar improvements to their apps.
Android and images infrastructure engineer Daniel Hugenroth explained how Spectrum works in a blog post.
The problem Spectrum sought to address is that the large file sizes of the high-resolutions images captured by smartphones were causing unreliable uploading on some mobile networks, and in some cases, transferring such large files was wasteful, as content-delivery networks often resize the images anyway.
Resizing images lowers the bandwidth that is necessary to send them, but the challenge was to do this while maintaining the quality of those images.
Hugenroth said Spectrum’s application-programming interface enables developers to focus on the desired output properties, rather than the individual steps that are necessary to achieve them. This allows Spectrum to choose the optimal way to handle each transcoding request from methods including lossless operations for cropping and rotating JPEG images and resizing.
The API uses “recipes” to help developers choose the optimal execution sequence, and those are provided by plugins. Hugenroth further explained, “For example, the JPEG plugin will provide recipes for the lossless cropping and rotation of JPEG images. All recipes are aggregated internally and sorted such that lossless and efficient recipes are at the top. With every request, Spectrum will iterate the list to execute the first matching (and therefore most efficient) recipe. The last resort is a generic recipe that can handle any request by decoding and encoding the image.”
He also noted that the core of spectrum was written in C++, allowing for consistent output when sharing between iOS and Android apps.
Hugenroth concluded, “We hope Spectrum will benefit developers in the same way it has helped Facebook create a better image production experience. In our apps, Spectrum has improved the reliability and quality of image uploads at large scale across our apps.”