# n-image **Repository Path**: mirrors_Financial-Times/n-image ## Basic Information - **Project Name**: n-image - **Description**: ❌ DEPRECATED Next responsive image component - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-24 - **Last Updated**: 2026-07-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # n-Image [![Circle CI](https://circleci.com/gh/Financial-Times/n-image.svg?style=svg)](https://circleci.com/gh/Financial-Times/n-image) ⚠️ This component is deprecated. Please use a plain `` or `` element to render images on the server and use [`o-lazy-load`](https://github.com/Financial-Times/o-lazy-load/) for client-side lazy-loading functionality. ⚠️ Bower component/Node module for responsive images. ## Usage n-image provides an `ImagePresenter` class which can be used with the `presenter` helper from `n-handlebars`, and also exports [DEPRECATED] `Image` and [DEPRECATED] `Picture` React components ### Using with the n-handlebars presenter By passing the context and some extra data options to the presenter helper, you will get a data structure returned to you. You can then use the partial provided in n-image/templates/image, or pick out the relevant properties. #### Complex example for responsive images ```html {{#nImagePresenter srcSet=image.url placeholder=image.ratio colspan='{ "default": 12, "M": 6, "L": 5.25 }' position='{"default": "left"}' widths="[131, 196, 276]" lazyLoad=true}} {{> n-image/templates/image }} {{/nImagePresenter}} ``` results in ```html
``` ### Responsive images There are two ways of rendering responsive images; a `srcset` and `sizes` attribute on the existing `img` element, or with the `picture` element. ### Image source If `src` is present in the data sent to the presenter, it will output data for a non-responsive attribute, with no srcSet or size data returned. #### `srcset` and `sizes` Attributes The srcset and sizes syntaxes are used to provide the browser with a list of image sources that are identical apart from their size. If `srcSet` (or `url` [DEPRECATED]) is provided, you MUST also provide `widths`. You SHOULD also provide **either** an array of pre-calculated `sizes` **or** get n-image to calculate your sizes attribute for you by providing arrays of `colspan` **and** `position` data. Colspan will default to `{'default': 12}` and position will default to `{'default': 'top'}`. Sizes ensure that the smallest possible image is served up, e.g. if you have an image with widths [980,500,322] inside a container that has a grid colspan of 12 for default grid (i.e. mobile first) and 4 for large viewports, this will ensure that the user is served up the 500px image in large viewports rather than a 980px image shrunk to fit the box by the browser. These are based on our standard breakpoints. Fuller examples of accepted data are documented in the [source code](src/presenters/image.js). Your srcSet URL should look something like `http://prod-upp-image-read.ft.com/97d6966c-993a-11e6-8f9b-70e3cabccfae` as it will be passed through the [build-image-service-url](src/helpers/build-image-service-url.js) to add in extra data for the build service. ### Lazy loading Images can be made to lazy load by adding `lazyLoad` to the data and setting it to `true`. Ensure that `main-client` is included in your client-facing JS. ### CSS A very minimal SASS file is available ``` @import 'n-image/main'; ``` ### DEPRECATED React components ``` import { Image } from '@financial-times/n-image'; A useful description ``` renders to ``` A useful description ``` #### `picture` Element The `picture` element is used when you need explicit control over which source is shown at set viewport sizes, i.e. images of different crops, zoom levels or aspect ratios are displayed at different breakpoints. e.g. ``` import { Picture } from '@financial-times/n-image'; ``` renders to ``` A useful description ``` ## Demo page `$ make demo`: Serves examples of the component locally (`http://localhost:5005`), using dummy data and in isolation from an app. This is done on a simple express app which renders a single demo page that calls the partial to exhibit, populating it with data from a fixture. ## Pa11y `$ make a11y`: Serves page of demo components, on which it runs [Pa11y](http://pa11y.org/) accessibility tests (errors flagging up accessibility infringements), which will also be run as part of the Continuous Integration (CI) process.