Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add new image resolvers #27443

Merged
merged 174 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
4814d60
Add static image plugin
ascorbic Sep 16, 2020
5509d90
Parse static image files
ascorbic Sep 16, 2020
6585d84
Fix package.json
ascorbic Sep 16, 2020
83b0321
Better static analysis
ascorbic Sep 17, 2020
b430e5a
Use jsx utils package
ascorbic Sep 18, 2020
96df1b8
Fix typings
ascorbic Sep 18, 2020
f98f56a
Typecheck fix
ascorbic Sep 18, 2020
e48da0a
Fix repo fields
ascorbic Sep 21, 2020
c11c2a4
Helpful warning
ascorbic Sep 21, 2020
7f16e80
Re-enable duotone
ascorbic Sep 22, 2020
146bd6e
Update readme
ascorbic Sep 22, 2020
f46f3e0
Improve typings
ascorbic Sep 22, 2020
65d06a4
Merge branch 'master' into feat/static-image-babel
ascorbic Sep 29, 2020
45a223f
wip fixed image fields for tracedSVG and webP
gillkyle Sep 30, 2020
836fe1d
handle fluid images as well
gillkyle Sep 30, 2020
97a5b77
Use require rather than JSON import
ascorbic Oct 1, 2020
46e5807
Watch files for changes, and use relative paths
ascorbic Oct 1, 2020
0d66f40
Merge branch 'add-missing-static-image-fields' into feat/static-image…
ascorbic Oct 1, 2020
5e41c30
Improve types
ascorbic Oct 1, 2020
0ebbf06
Add type
ascorbic Oct 2, 2020
41a3cce
Merge branch 'master' into feat/static-image-babel
ascorbic Oct 2, 2020
12597fa
Update yarn.lock
ascorbic Oct 2, 2020
4036bb3
Add lots of comments and remove unused stuff
ascorbic Oct 2, 2020
b548429
Create and watch our own nodes
ascorbic Oct 2, 2020
3242599
Update readme
ascorbic Oct 2, 2020
935e91a
Merge remote-tracking branch 'origin/master' into feat/static-image-b…
ascorbic Oct 2, 2020
70616e2
Update deps
ascorbic Oct 2, 2020
67ea9ef
Only watch in develop
ascorbic Oct 2, 2020
4f68363
Rename to gatsby-plugin-image
ascorbic Oct 5, 2020
f5dc9f7
Rearrange, ready for merger
ascorbic Oct 5, 2020
13e1ca8
Import @wardpeet 's gatsby-image-netxtgen
ascorbic Oct 5, 2020
6569d06
Update typings and further merge packages
ascorbic Oct 5, 2020
f3598f0
Build babel plugin
ascorbic Oct 5, 2020
94e4b7e
More merging
ascorbic Oct 5, 2020
7635d59
Add server/browser static image variants
ascorbic Oct 5, 2020
5060df6
include webpack changes
Oct 5, 2020
812ab51
change error message to use gatsby-plugin-image
Oct 5, 2020
80c9155
Merge remote-tracking branch 'origin/master' into feat/static-image-b…
ascorbic Oct 6, 2020
5f1aa5a
Fix compat compilation
ascorbic Oct 6, 2020
4f8824e
Fix SSR
ascorbic Oct 6, 2020
5155374
Merge readmes
ascorbic Oct 6, 2020
e93480f
Build browser bundle
ascorbic Oct 6, 2020
e581396
Export correctly from browser entry point
ascorbic Oct 6, 2020
f6e1156
Remove hook import
ascorbic Oct 6, 2020
24ffaa2
Apply suggestions from code review
ascorbic Oct 6, 2020
ff4d0a9
Merge branch 'feat/static-image-babel' of github.com:gatsbyjs/gatsby …
ascorbic Oct 6, 2020
ea4bf65
Changes from review
ascorbic Oct 6, 2020
2e5912f
add path prefix, static image do e2e test
Oct 6, 2020
aee3dc9
Add prepare script
ascorbic Oct 7, 2020
9ecea93
Apply README suggestions from code review
ascorbic Oct 7, 2020
284d34c
Fix image component in e2e test
ascorbic Oct 7, 2020
8badae4
Better error messages
ascorbic Oct 7, 2020
121e344
Merge branch 'feat/static-image-babel' of github.com:gatsbyjs/gatsby …
ascorbic Oct 7, 2020
618bd75
Prefer svg over base64. Warn for unsupported art direction
ascorbic Oct 7, 2020
e2d84d8
Fix type
ascorbic Oct 7, 2020
f84853f
Use "layout" instead of fixed/fluid
ascorbic Oct 7, 2020
31b8594
add static images to production runtime site
Oct 7, 2020
cc7c571
add path prefix tests
Oct 7, 2020
5426dcf
Reorg types. Change private prop name
ascorbic Oct 7, 2020
a3305a9
Merge branch 'feat/static-image-babel' of github.com:gatsbyjs/gatsby …
ascorbic Oct 7, 2020
a80fa20
initial gatsby static image tests
Oct 7, 2020
3f15544
add test suite to circle ci
Oct 7, 2020
d891b8d
add test suite to circle ci
Oct 7, 2020
0a19484
add test suite to circle ci
Oct 7, 2020
c97041c
remove unused imports, use valid fluid setting
Oct 7, 2020
1c2c89e
Use new fluid props syntax
ascorbic Oct 8, 2020
127840e
Better var name
ascorbic Oct 8, 2020
8e93857
update tests
Oct 8, 2020
8125d34
remove tests that no longer match the expected DOM
Oct 8, 2020
a76ea81
Merge branch 'feat/static-image-babel' of github.com:gatsbyjs/gatsby …
ascorbic Oct 8, 2020
5aa7ec6
Merge remote-tracking branch 'origin/master' into feat/static-image-b…
ascorbic Oct 9, 2020
f999a45
More compat-fixes
ascorbic Oct 9, 2020
81e7ee7
Change classname to match old version
ascorbic Oct 9, 2020
df2e14b
Compat improvements
ascorbic Oct 9, 2020
a4d991e
Update tests to match new classname
ascorbic Oct 9, 2020
2a8d141
Merge remote-tracking branch 'upstream/master' into feat/static-image…
Oct 9, 2020
6d05bc1
Merge remote-tracking branch 'origin/master' into feat/static-image-b…
ascorbic Oct 13, 2020
46f33b7
v0.0.1
ascorbic Oct 13, 2020
b2620c7
Add readme caveat
ascorbic Oct 13, 2020
870ceff
Update version in packages
ascorbic Oct 13, 2020
5db8d30
Remove forcewrapper
ascorbic Oct 13, 2020
c095f4b
wip
ascorbic Oct 13, 2020
02e6495
have static image use gatsbyImageProps function
Oct 13, 2020
4de8330
Merge remote-tracking branch 'origin/master' into feat/image-resolvers
ascorbic Oct 14, 2020
683b57a
Upgrade sharp
ascorbic Oct 14, 2020
559b571
Fix static image type
ascorbic Oct 14, 2020
d52c4a0
First steps to update API
ascorbic Oct 14, 2020
13e3423
Add descriptions
ascorbic Oct 14, 2020
1d440ce
Merge remote-tracking branch 'origin/master' into feat/static-image-b…
ascorbic Oct 14, 2020
03e894a
Merge branch 'feat/static-image-babel' into feat/image-resolvers
ascorbic Oct 14, 2020
60d554f
TypeScript fixes
ascorbic Oct 14, 2020
d5b1f1a
Compile ts
ascorbic Oct 14, 2020
f78bb88
Merge remote-tracking branch 'origin/master' into feat/image-resolvers
ascorbic Oct 15, 2020
6a0c0b0
Add @gillkyle's calculateImageSizes util funciton
ascorbic Oct 15, 2020
86f9af0
remove unused file
Oct 15, 2020
9e1f556
unbump sharp until sharp PR is merged
Oct 15, 2020
ffddd6f
comment out import
Oct 15, 2020
70cdb59
update snapshots
Oct 15, 2020
c1558f2
change JSX to take image prop
Oct 15, 2020
3127a0a
static image uses new image props
Oct 15, 2020
4a31afb
Rename all the things
ascorbic Oct 15, 2020
4b57129
Turns out it wasn't all of them
ascorbic Oct 15, 2020
a1d967d
Update schema
ascorbic Oct 15, 2020
b601e9d
fix intrinsic issue 1px problem, still doesn't seem to reach the corr…
Oct 15, 2020
a5ba190
Fix layout
ascorbic Oct 16, 2020
1e1dba6
Update readme
ascorbic Oct 16, 2020
e1b3b62
Merge remote-tracking branch 'origin/master' into feat/image-resolvers
ascorbic Oct 16, 2020
edb5a7a
Fix dep
ascorbic Oct 16, 2020
8449710
Shouldn;t be in this
ascorbic Oct 16, 2020
1888a2f
Fix sharp function name
ascorbic Oct 16, 2020
8568329
Version
ascorbic Oct 16, 2020
483adb8
Merge remote-tracking branch 'origin/master' into feat/image-resolvers
ascorbic Oct 16, 2020
6abf47d
What is this snapshot out of date?
ascorbic Oct 16, 2020
f30d823
Add a helper funciton
ascorbic Oct 16, 2020
abd9052
Make backgroundColor work
ascorbic Oct 16, 2020
b0e1a39
update layout for images
Oct 16, 2020
dc905ac
no longer using base64 so remove that test
Oct 16, 2020
6307d9b
placeholder not getting passed from static, so this is still busted
Oct 16, 2020
cde4d27
Fix passing of props
ascorbic Oct 16, 2020
267af4d
Merge branch 'feat/image-resolvers' of github.com:gatsbyjs/gatsby int…
ascorbic Oct 16, 2020
a02fadb
Add TODO comments
ascorbic Oct 16, 2020
03e26e8
Merge remote-tracking branch 'origin/master' into feat/image-resolvers
ascorbic Oct 19, 2020
2a78089
Merge remote-tracking branch 'origin/master' into feat/image-resolvers
ascorbic Oct 19, 2020
087d792
Export batch queue function
ascorbic Oct 19, 2020
48ffac8
Handle the default sizes elsewhere, as it depends on layout
ascorbic Oct 19, 2020
99d5c77
feat(gatsby-plugin-sharp): create image sizes helper (#27554)
gillkyle Oct 20, 2020
dd903e7
Use passed-in reporter
ascorbic Oct 20, 2020
6f96517
Use shared function to handle fit calculation
ascorbic Oct 20, 2020
b048019
Return presentationW/H and aspect ratio from sizes function
ascorbic Oct 20, 2020
0924270
Round sizes
ascorbic Oct 20, 2020
050450d
Use new resizing functions
ascorbic Oct 20, 2020
b49e8c8
default layout wasn't passed to createImageSizes
Oct 20, 2020
0809801
add fixed width default and round calculated height
Oct 20, 2020
f65ed05
reversed logic for aspect ratio calculations
gillkyle Oct 20, 2020
2a08433
Merge remote-tracking branch 'origin' into feat/image-resolvers
ascorbic Oct 21, 2020
ee0f51a
Correct description for outputPixelDensities resolver
ascorbic Oct 21, 2020
22f4e8a
Remove log
ascorbic Oct 21, 2020
9523fc3
Handle null image in SSR
ascorbic Oct 21, 2020
d6c0b3b
Version fix
ascorbic Oct 21, 2020
59ee72c
fix(gatsby-plugin-utils): skip libcheck during typegen
ascorbic Oct 21, 2020
046a614
Remove unused func
ascorbic Oct 21, 2020
35df109
Remove dominantColor from fixed and fluid
ascorbic Oct 22, 2020
0108c2c
sizing code for KG to drive refactor
Oct 22, 2020
130ba02
remove isSmaller
gillkyle Oct 22, 2020
8fbca1d
fix tests
gillkyle Oct 22, 2020
3c264eb
Merge remote-tracking branch 'origin' into feat/image-resolvers
ascorbic Oct 23, 2020
838b01a
Fix sizes and srcset generation
ascorbic Oct 23, 2020
781af53
Merge branch 'feat/image-resolvers' of github.com:gatsbyjs/gatsby int…
ascorbic Oct 23, 2020
92768e1
Add object-fit
ascorbic Oct 23, 2020
72645ad
rename placeholder function for consistency
Oct 23, 2020
2f73b31
Update readme
ascorbic Oct 23, 2020
d7d8617
Merge branch 'feat/image-resolvers' of github.com:gatsbyjs/gatsby int…
ascorbic Oct 23, 2020
abda06a
fix path prefix images
Oct 23, 2020
a086ef7
Merge branch 'feat/image-resolvers' of https://github.com/gatsbyjs/ga…
Oct 23, 2020
2a9b0fe
fix sizing when larger image dimensions are requested, fix warning as…
Oct 23, 2020
f3e114a
rename file to match constrained naming
Oct 23, 2020
b5c546a
Changes from review
ascorbic Oct 26, 2020
89764a8
Merge remote-tracking branch 'origin' into feat/image-resolvers
ascorbic Oct 26, 2020
950b131
Add alpha warning
ascorbic Oct 26, 2020
2568f00
Change from review
ascorbic Oct 26, 2020
43bb48b
fix placeholder opacity
Oct 26, 2020
fb616c3
fix placeholder bug
Oct 26, 2020
3508808
only change placeholder size for background color div
Oct 26, 2020
d66f3b2
tests: Add visual regression tests (#27619)
ascorbic Oct 27, 2020
9c3b7cb
Fix e2e test
ascorbic Oct 27, 2020
d0ff2c8
Merge branch 'feat/image-resolvers' of github.com:gatsbyjs/gatsby int…
ascorbic Oct 27, 2020
f9e36bb
Merge remote-tracking branch 'origin' into feat/image-resolvers
ascorbic Oct 27, 2020
4cfc7c3
Merge remote-tracking branch 'origin' into feat/image-resolvers
ascorbic Oct 27, 2020
de6c6a1
dont flash placeholder image when removing opacity
gillkyle Oct 27, 2020
b0c27ec
Merge branch 'feat/image-resolvers' of github.com:gatsbyjs/gatsby int…
gillkyle Oct 27, 2020
d8675ce
Fix dependency
ascorbic Oct 27, 2020
96118ca
add analagous tests for static image
gillkyle Oct 28, 2020
a33d4f6
Add width to constrained images and update snapshots
ascorbic Oct 29, 2020
b4a8e60
Use float
ascorbic Oct 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/gatsby-plugin-sharp/src/image-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { traceSVG, getImageSizeAsync, base64, batchQueueImageResizing } from "."
import type { SharpInstance } from "sharp"
import sharp from "./safe-sharp"
import { createTransformObject } from "./plugin-options"
import { meta } from "joi"
laurieontech marked this conversation as resolved.
Show resolved Hide resolved
export interface ISharpGatsbyImageArgs {
layout?: "fixed" | "fluid" | "constrained"
placeholder?: "tracedSVG" | "dominantColor" | "blurred" | "none"
Expand Down Expand Up @@ -70,6 +71,7 @@ export interface IImageDataProps {
export interface IImageDataArgs {
file: FileNode
args: ISharpGatsbyImageArgs
pathPrefix: string
cache: GatsbyCache
reporter: Reporter
}
Expand All @@ -94,6 +96,7 @@ export async function generateImageData({
presentationWidth: number
presentationHeight: number
aspectRatio: number
isTopSizeOverriden: boolean
} = calculateImageSizes({
file,
layout,
Expand Down Expand Up @@ -123,13 +126,22 @@ export async function generateImageData({

const srcSet = getSrcSet(images)

const widthOfMaxSize = Math.min(imageSizes.presentationWidth, metadata.width)
const widthOfMaxSize = imageSizes.isTopSizeOverriden
? metadata.width
: imageSizes.presentationWidth

const sizes = args.sizes || getSizes(widthOfMaxSize, layout)

const primaryIndex = imageSizes.sizes.findIndex(
size => size === widthOfMaxSize
)

if (primaryIndex === -1) {
reporter.panic(
`No image of the specified size found. Images may not have been processed correctly.`
)
}

const primaryImage = images[primaryIndex]

if (!images?.length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

images should always be a [] unsure why ou need the ?

Suggested change
if (!images?.length) {
if (!images.length) {

Expand Down
45 changes: 25 additions & 20 deletions packages/gatsby-plugin-sharp/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ export function fixedImageSizes({
height = calculated.height
aspectRatio = calculated.aspectRatio
}

if (!width && !height) {
width = 400
}
Expand All @@ -182,8 +181,26 @@ export function fixedImageSizes({
width = Math.round(height * aspectRatio)
}

let originalWidth = width
if (imgDimensions.width < width || imgDimensions.height < height) {
const originalWidth = width // will use this for presentationWidth, don't want to lose it

const isTopSizeOverriden =
imgDimensions.width < width || imgDimensions.height < height

// If the image is smaller than what's requested, warn the user that it's being processed as such
// print out this message with the necessary information before we overwrite it for sizing
if (isTopSizeOverriden) {
const fixedDimension = imgDimensions.width < width ? `width` : `height`
reporter.warn(`
The requested ${fixedDimension} "${
fixedDimension === `width` ? width : height
}px" for a resolutions field for
the file ${file.absolutePath}
was larger than the actual image ${fixedDimension} of ${
imgDimensions[fixedDimension]
}px!
If possible, replace the current image with a larger one.
`)

width = imgDimensions.width
height = imgDimensions.height
}
Expand All @@ -193,27 +210,12 @@ export function fixedImageSizes({
.map(density => Math.round(density * width))
.filter(size => size <= imgDimensions.width)

// If there's no fixed images after filtering (e.g. image is smaller than what's
// requested, add back the original so there's at least something)
if (sizes.length === 0) {
sizes.push(width)
const fixedDimension = width === undefined ? `height` : `width`
reporter.warn(`
The requested ${fixedDimension} "${
fixedDimension === `width` ? width : height
}px" for a resolutions field for
the file ${file.absolutePath}
was larger than the actual image ${fixedDimension} of ${
imgDimensions[fixedDimension]
}px!
If possible, replace the current image with a larger one.
`)
}
return {
sizes,
aspectRatio,
presentationWidth: originalWidth,
presentationHeight: Math.round(originalWidth / aspectRatio),
isTopSizeOverriden,
}
}

Expand Down Expand Up @@ -269,7 +271,9 @@ export function fluidImageSizes({
}

let originalMaxWidth = maxWidth
if (imgDimensions.width < maxWidth || imgDimensions.height < maxHeight) {
let isTopSizeOverriden =
imgDimensions.width < maxWidth || imgDimensions.height < maxHeight
if (isTopSizeOverriden) {
maxWidth = imgDimensions.width
maxHeight = imgDimensions.height
}
Expand Down Expand Up @@ -302,6 +306,7 @@ export function fluidImageSizes({
aspectRatio,
presentationWidth: originalMaxWidth,
presentationHeight: Math.round(originalMaxWidth / aspectRatio),
isTopSizeOverriden,
}
}

Expand Down