Metadata is a powerful tool when working with images. It can tell you the dimensions of your image, DPI, camera EXIF data, and more—and each piece of data is a signal you can use with imgix to display your images to their best advantage with the JSON Output Format (
All of the other imgix output formats are image formats like JPEG, GIF, PNG, WebP, or automatically determined by Automatic Content Negotiation. With the new JSON Output Format, you can read information about your images in a familiar, structured format. This opens up a host of new possibilities.
The imgix JSON Output Format will cause an image request to return a JSON document rather than an image. This payload will have the MIME type
application/json and represent several different aspects of the input image. This is done by adding
fm=json to your imgix URL.
Using the JSON Output Format, you can read the DPI, color depth, color profile information, pixel dimensions, EXIF data, and more from source images. By default, imgix strips all image metadata for size and privacy concerns. When using the JSON Output Format, however, it will not strip that data and will format it as the response. Here is an example output for a simple JPEG input image:
Different input formats will include different keys in their JSON output payloads. Please experiment with your own input images to see which keys will be included in the output document. For a more complex example, please click on the image below.
Using the new JSON Output Format, you can do more than just manipulate images with imgix. You can now reason about them as well. This has already led to richer applications for the customers using this feature.
To demonstrate some of the JSON Output Format's capabilities, we’ve put together a CodePen to show how to maintain the aspect ratio of several user-generated photos. Without access to the metadata, we would have to download the image and store its dimensions server-side to accomplish the same result.