{"id":14991078,"url":"https://github.com/moxystudio/react-contentful-image","last_synced_at":"2025-07-03T22:36:58.785Z","repository":{"id":45548307,"uuid":"257658628","full_name":"moxystudio/react-contentful-image","owner":"moxystudio","description":"A react image renderer that uses the Contentful Images API.","archived":false,"fork":false,"pushed_at":"2023-01-06T03:57:29.000Z","size":2621,"stargazers_count":13,"open_issues_count":11,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-25T23:04:48.526Z","etag":null,"topics":["base","react"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moxystudio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-21T17:00:22.000Z","updated_at":"2024-12-05T08:51:19.000Z","dependencies_parsed_at":"2023-02-05T06:31:53.175Z","dependency_job_id":null,"html_url":"https://github.com/moxystudio/react-contentful-image","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":"moxystudio/react-lib-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moxystudio%2Freact-contentful-image","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moxystudio%2Freact-contentful-image/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moxystudio%2Freact-contentful-image/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moxystudio%2Freact-contentful-image/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moxystudio","download_url":"https://codeload.github.com/moxystudio/react-contentful-image/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248511251,"owners_count":21116375,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["base","react"],"created_at":"2024-09-24T14:21:26.559Z","updated_at":"2025-04-12T03:25:36.265Z","avatar_url":"https://github.com/moxystudio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-contentful-image\n\n[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][build-status-image]][build-status-url] [![Coverage Status][codecov-image]][codecov-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url]\n\n[npm-url]:https://npmjs.org/package/@moxy/react-contentful-image\n[downloads-image]:https://img.shields.io/npm/dm/@moxy/react-contentful-image.svg\n[npm-image]:https://img.shields.io/npm/v/@moxy/react-contentful-image.svg\n[build-status-url]:https://github.com/moxystudio/react-contentful-image/actions\n[build-status-image]:https://img.shields.io/github/workflow/status/moxystudio/react-contentful-image/Node%20CI/master\n[codecov-url]:https://codecov.io/gh/moxystudio/react-contentful-image\n[codecov-image]:https://img.shields.io/codecov/c/github/moxystudio/react-contentful-image/master.svg\n[david-dm-url]:https://david-dm.org/moxystudio/react-contentful-image\n[david-dm-image]:https://img.shields.io/david/moxystudio/react-contentful-image.svg\n[david-dm-dev-url]:https://david-dm.org/moxystudio/react-contentful-image?type=dev\n[david-dm-dev-image]:https://img.shields.io/david/dev/moxystudio/react-contentful-image.svg\n\nA react image renderer that uses the Contentful Images API.\n\n## Installation\n\n```sh\n$ npm install @moxy/react-contentful-image\n```\n\nThis library is written in modern JavaScript and is published in both CommonJS and ES module transpiled variants. If you target older browsers please make sure to transpile accordingly.\n\n## Motivation\n\n[Contentful](https://www.contentful.com/) provides a very powerful [Images API](https://www.contentful.com/developers/docs/references/images-api/) that besides retrieving image files, provides manipulation features such as resizing, cropping and compressing.\n\nThis react component returns a `\u003cpicture\u003e` element. If no manipulations are made, the `\u003cpicture\u003e` contains at least one `\u003csource\u003e` element, otherwise it will have two `\u003csource\u003e`. It also contains the native `\u003cimg\u003e` as fallback for browsers that do not support the `\u003cpicture\u003e` element.\n\n## Usage\n\n```js\nimport React from 'react';\nimport ContentfulImage from '@moxy/react-contentful-image';\n\nconst src = \"//images.ctfassets.net/yadj1kx9rmg0/wtrHxeu3zEoEce2MokCSi/cf6f68efdcf625fdc060607df0f3baef/quwowooybuqbl6ntboz3.jpg\";\n\nconst MyComponent = (props) =\u003e (\n    \u003cdiv {...props}\u003e\n        \u003cContentfulImage\n            image={ src }\n            format=\"png\"\n            resize={ { width: 100, height: 100 } } /\u003e\n    \u003c/div\u003e\n);\n\nexport default MyComponent;\n```\n\n## API\n\nBesides the following supported props by the `\u003cContentfulImage\u003e` component, additional props will be spread to the `\u003cimg\u003e` element.\n\n#### image\n\nType: `string` or `object` | Required: `true`\n\nThe actual image. It can be provided as an URL (`string`) or as a Contentful asset (`object`).\n\n\nA Contentful asset usually has the following structure:\n\n```js\n{\n    // ...\n    fields: {\n        // ...\n        file: {\n            // ...\n            url: 'my-image-url',\n            // ...\n        },\n        // ...\n    },\n    // ...\n}\n```\n\nThus, you can pass it to this component and the image will be properly handled.\n\nExample:\n\n```js\nconst src = 'my-image-url';\n\n\u003cContentfulImage image={ src } /\u003e\n```\n\nor\n\n```js\nconst { image } = page.fields;\n\n\u003cContentfulImage image={ image } /\u003e\n```\n\n#### format\n\nType: `string` | Required: `false` | Default: `webp`\n\nThe new format to convert the image. The possibilities are:\n- `webp`\n- `jpg`\n- `png`\n- `progressive jpg`\n- `8bit png`\n\nExample:\n\n```js\n\u003cContentfulImage\n    image={ src }\n    format=\"progressive jpg\" /\u003e\n```\n\nIf no `format` prop is passed, this component will convert the image to [`webp`](https://developers.google.com/speed/webp) by default as it provides small images weight with high visual quality. The example above will override this default value and will convert the image to `progressive jpg`. If you want to keep your image format with no conversions, please see [`optimize` prop](#optimize).\n\nℹ️ Read more about Contentful Images API format conversion [here](https://www.contentful.com/developers/docs/references/images-api/#/reference/changing-formats).\n\n#### resize\n\nType: `object` | Required: `false`\n\nResizing configuration object. This object has the following shape:\n- `width` - Desired width\n- `height` - Desired height\n- `behavior` - Specifies the resizing behavior. The possible values are:\n  - `pad`\n  - `fill`\n  - `scale`\n  - `crop`\n  - `thumb`\n- `focusArea` - Specifies the focus area when resizing. The possible values are:\n  - `top`\n  - `right`\n  - `bottom`\n  - `left`\n  - `center`\n  - `top_right`\n  - `top_left`\n  - `bottom_right`\n  - `bottom_left`\n  - `face`\n  - `faces`\n\nExample:\n\n```js\nconst resizeValues = {\n    width: 100,\n    height: 100,\n    behavior: 'crop',\n    focusArea: 'top_right'\n};\n\n// ...\n\n\u003cContentfulImage\n    image={ src }\n    resize={ resizeValues } /\u003e\n```\n\n⚠️ Please, note the following warnings:\n- The maximum value for both `width` and `height` properties is 4000 pixels.\n- `focusArea` property won't have effect on the default or `scale` behavior.\n\nℹ️ Read more about resizing images with Contentful Images API [here](https://www.contentful.com/developers/docs/references/images-api/#/reference/resizing-\u0026-cropping).\n\n#### cropRadius\n\nType: `string` or `number` | Required: `false`\n\nAdd rounded corners or create a circle/ellipsis. The possible values are:\n\n- `max` keyword - Creates a full circle/ellipsis\n- The size of the corner radius in pixels\n\nExample:\n\n```js\n\u003cContentfulImage\n    image={ src }\n    cropRadius=\"max\" /\u003e\n\n// or\n\n\u003cContentfulImage\n    image={ src }\n    cropRadius={ 30 } /\u003e\n```\n\nℹ️ Read more about cropping images with Contentful Images API [here](https://www.contentful.com/developers/docs/references/images-api/#/reference/resizing-\u0026-cropping/crop-rounded-corners-\u0026-circle-elipsis).\n\n#### quality\n\nType: `number` | Required: `false`\n\nSets the quality of the image. The value must be between **1** and **100**.\n\nExample:\n\n```js\n\u003cContentfulImage\n    image={ src }\n    format=\"jpg\"\n    quality={ 10 } /\u003e\n```\n\n⚠️ This value will be ignored for 8-bit PNGs.\n\nℹ️ Read more about changing the image quality with Contentful Images API [here](https://www.contentful.com/developers/docs/references/images-api/#/reference/image-manipulation/quality).\n\n#### backgroundColor\n\nType: `string` | Required: `false`\n\nSets the background color when using `cropRadius` or the `pad` behavior. Color hex code is expected as the value.\n\nExample:\n\n```js\n\u003cContentfulImage\n    image={ src }\n    cropRadius=\"max\"\n    backgroundColor=\"#FFFFFF\" /\u003e\n```\n\nℹ️ Read more about changing the image background color with Contentful Images API [here](https://www.contentful.com/developers/docs/references/images-api/#/reference/image-manipulation/background-color).\n\n#### optimize\n\nType: `bool` | Required: `false` | Default: `true`\n\nIf no `format` is passed, this component will use `webp` format as default. To convert to any other format, just use [`format` prop](#format) to override the default value. If you want to keep your image with no format manipulations set this prop to `false`.\n\nExample:\n\n```js\n\u003cContentfulImage\n    image={ src }\n    optimize={ false } /\u003e\n```\n\n\n## Tests\n\n```sh\n$ npm test\n$ npm test -- --watch # during development\n```\n\n## Demo\n\nA demo [Next.js](https://nextjs.org/) project is available in the [`/demo`](./demo) folder so you can try out this component.\n\nFirst, build the `react-contentful-image` project with:\n\n```sh\n$ npm run build\n```\n\nTo run the demo, do the following inside the demo's folder:\n\n```sh\n$ npm i\n$ npm run dev\n```\n\n*Note: Everytime a change is made to the package a rebuild is required to reflect those changes on the demo.*\n\n## License\n\nReleased under the [MIT License](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoxystudio%2Freact-contentful-image","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoxystudio%2Freact-contentful-image","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoxystudio%2Freact-contentful-image/lists"}