Skip to content

Commit

Permalink
chore(gatsby-plugin-sharp): Remove sizeByPixelDensity option (#33468)
Browse files Browse the repository at this point in the history
  • Loading branch information
LekoArts committed Oct 11, 2021
1 parent 87bd10a commit d467372
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 45 deletions.
2 changes: 0 additions & 2 deletions packages/gatsby-plugin-sharp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ for more details.
- `webpQuality` (int)
- `srcSetBreakpoints` (array of int, default: [])
- `background` (string, default: 'rgba(0,0,0,1)')
- [deprecated] `sizeByPixelDensity` (bool, default: false)
- Pixel density is only used in vector images, which Gatsby’s implementation of Sharp doesn’t support. This option is currently a no-op and will be removed in the next major version of Gatsby.

#### Returns

Expand Down
17 changes: 0 additions & 17 deletions packages/gatsby-plugin-sharp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,24 +432,7 @@ async function stats({ file, reporter }) {

async function fluid({ file, args = {}, reporter, cache }) {
const options = healOptions(getPluginOptions(), args, file.extension)
if (options.sizeByPixelDensity) {
/*
* We learned that `sizeByPixelDensity` is only valid for vector images,
* and Gatsby’s implementation of Sharp doesn’t support vector images.
* This means we should remove this option in the next major version of
* Gatsby, but for now we can no-op and warn.
*
* See https://github.com/gatsbyjs/gatsby/issues/12743
*
* TODO: remove the sizeByPixelDensity option in the next breaking release
*/
reporter.warn(
`the option sizeByPixelDensity is deprecated and should not be used. It will be removed in the next major release of Gatsby.`
)
}

// Account for images with a high pixel density. We assume that these types of
// images are intended to be displayed at their native resolution.
let metadata
try {
const pipeline = sharp()
Expand Down
1 change: 0 additions & 1 deletion packages/gatsby-plugin-sharp/src/plugin-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const generalArgs = {
pathPrefix: ``,
toFormat: ``,
toFormatBase64: ``,
sizeByPixelDensity: false,
rotate: 0,
}

Expand Down
19 changes: 9 additions & 10 deletions packages/gatsby-remark-images-contentful/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ plugins: [

## Options

| Name | Default | Description |
| ---------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `maxWidth` | `650` | The `maxWidth` in pixels of the `div` where the markdown will be displayed. This value is used when deciding what the width of the various responsive thumbnails should be. |
| `linkImagesToOriginal` | `true` | Add a link to each image to the original image. Sometimes people want to see a full-sized version of an image e.g. to see extra detail on a part of the image and this is a convenient and common pattern for enabling this. Set this option to false to disable this behavior. |
| `showCaptions` | `false` | Add a caption to each image with the contents of the title attribute, when this is not empty. Set this option to true to enable this behavior. |
| `sizeByPixelDensity` | `false` | Analyze images' pixel density to make decisions about target image size. This is what GitHub is doing when embedding images in tickets. This is a useful setting for documentation pages with a lot of screenshots. It can have unintended side effects on high-pixel density artworks.<br /><br />Example: A screenshot made on a retina screen with a resolution of 144 (e.g. Macbook) and a width of 100px, will be rendered at 50px. |
| `wrapperStyle` | | Add custom styles to the div wrapping the responsive images. Use regular CSS syntax, e.g. `margin-bottom:10px; background: red;` |
| `backgroundColor` | `white` | Set the background color of the image to match the background of your design |
| `withWebp` | `false` | Additionally generate WebP versions alongside your chosen file format. They are added as a srcset with the appropriate mimetype and will be loaded in browsers that support the format. |
| `loading` | `lazy` | Set the browser's native lazy loading attribute. One of `lazy`, `eager` or `auto`. |
| Name | Default | Description |
| ---------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `maxWidth` | `650` | The `maxWidth` in pixels of the `div` where the markdown will be displayed. This value is used when deciding what the width of the various responsive thumbnails should be. |
| `linkImagesToOriginal` | `true` | Add a link to each image to the original image. Sometimes people want to see a full-sized version of an image e.g. to see extra detail on a part of the image and this is a convenient and common pattern for enabling this. Set this option to false to disable this behavior. |
| `showCaptions` | `false` | Add a caption to each image with the contents of the title attribute, when this is not empty. Set this option to true to enable this behavior. |
| `wrapperStyle` | | Add custom styles to the div wrapping the responsive images. Use regular CSS syntax, e.g. `margin-bottom:10px; background: red;` |
| `backgroundColor` | `white` | Set the background color of the image to match the background of your design |
| `withWebp` | `false` | Additionally generate WebP versions alongside your chosen file format. They are added as a srcset with the appropriate mimetype and will be loaded in browsers that support the format. |
| `loading` | `lazy` | Set the browser's native lazy loading attribute. One of `lazy`, `eager` or `auto`. |

## Troubleshooting

Expand Down
8 changes: 2 additions & 6 deletions packages/gatsby-remark-images-contentful/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ const buildResponsiveSizes = async (
)

const { width, height, density } = metadata
const { sizeByPixelDensity, maxWidth, sizes } = options
const { maxWidth, sizes } = options
const aspectRatio = width / height
const pixelRatio =
sizeByPixelDensity && typeof density === `number` && density > 0
? density / 72
: 1

const presentationWidth = Math.min(maxWidth, Math.round(width / pixelRatio))
const presentationWidth = Math.min(maxWidth, width)
const presentationHeight = Math.round(presentationWidth * (height / width))
const sizesQuery =
sizes || `(max-width: ${presentationWidth}px) 100vw, ${presentationWidth}px`
Expand Down
1 change: 0 additions & 1 deletion packages/gatsby-remark-images/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ a reserved keyword `GATSBY_EMPTY_ALT` can be used.
| `linkImagesToOriginal` | `true` | Add a link to each image to the original image. Sometimes people want to see a full-sized version of an image e.g. to see extra detail on a part of the image and this is a convenient and common pattern for enabling this. Set this option to `false` to disable this behavior. |
| `showCaptions` | `false` | Add a caption to each image with the contents of the title attribute, when this is not empty. If the title attribute is empty but the alt attribute is not, it will be used instead. Set this option to true to enable this behavior. You can also pass an array instead to specify which value should be used for the caption — for example, passing `['alt', 'title']` would use the alt attribute first, and then the title. When this is set to `true` it is the same as passing `['title', 'alt']`. If you just want to use the title (and omit captions for images that have alt attributes but no title), pass `['title']`. |
| `markdownCaptions` | `false` | Parse the caption as markdown instead of raw text. Ignored if `showCaptions` is `false`. |
| `sizeByPixelDensity` | `false` | [deprecated] Pixel density is only used in vector images, which Gatsby’s implementation of Sharp doesn’t support. This option is currently a no-op and will be removed in the next major version of Gatsby. |
| `wrapperStyle` | | Add custom styles to the div wrapping the responsive images. Use the syntax for the style attribute e.g. `margin-bottom:10px; background: red;` or a function returning a style string which receives the information about the image you can use to dynamically set styles based on the `aspectRatio` for example. |
| `backgroundColor` | `white` | Set the background color of the image to match the background image of your design.<br /><br />**Note:**<br />- set this option to `transparent` for a transparent image background.<br /> - set this option to `none` to completely remove the image background. |
| `quality` | `50` | The quality level of the generated files. |
Expand Down
3 changes: 0 additions & 3 deletions packages/gatsby-remark-images/src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ describe(`pluginOptionsSchema`, () => {
`"linkImagesToOriginal" must be a boolean`,
`"showCaptions" must be one of [boolean, array]`,
`"markdownCaptions" must be a boolean`,
`"sizeByPixelDensity" must be a boolean`,
`"wrapperStyle" must be one of [object, string]`,
`"backgroundColor" must be a string`,
`"quality" must be a number`,
Expand All @@ -27,7 +26,6 @@ describe(`pluginOptionsSchema`, () => {
linkImagesToOriginal: `This should be a boolean`,
showCaptions: `This should be a boolean`,
markdownCaptions: `This should be a boolean`,
sizeByPixelDensity: `This should be a boolean`,
wrapperStyle: true,
backgroundColor: 123,
quality: `This should be a number`,
Expand All @@ -49,7 +47,6 @@ describe(`pluginOptionsSchema`, () => {
linkImagesToOriginal: false,
showCaptions: true,
markdownCaptions: true,
sizeByPixelDensity: true,
wrapperStyle: { marginTop: `1rem`, padding: `1.5rem`, color: `blue` },
backgroundColor: `red`,
quality: 77,
Expand Down
5 changes: 0 additions & 5 deletions packages/gatsby-remark-images/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ exports.pluginOptionsSchema = function ({ Joi }) {
.description(
`Parse the caption as markdown instead of raw text. Ignored if showCaptions is false.`
),
sizeByPixelDensity: Joi.boolean()
.default(false)
.description(
`[deprecated] Pixel density is only used in vector images, which Gatsby’s implementation of Sharp doesn’t support. This option is currently a no-op and will be removed in the next major version of Gatsby.`
),
wrapperStyle: Joi.alternatives().try(
Joi.object({}).unknown(true),
Joi.function().maxArity(1),
Expand Down

0 comments on commit d467372

Please sign in to comment.