Skip to content

Commit 70510ab

Browse files
committed
feat: adds blur-up effect on images loading
1 parent b927308 commit 70510ab

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

src/getFixedGatsbyImage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import getBasicImageProps from './utils/getBasicImageProps'
2-
import buildUrl from './utils/buildImageUrl'
2+
import buildUrl, { buildLowFiUrl } from './utils/buildImageUrl'
33
import { isWebP } from './utils/helpers'
44
import { sizeMultipliersFixed, defaultFixedOptions } from './defaults'
55

@@ -87,7 +87,7 @@ function getFixedGatsbyImage(image, args = {}) {
8787
// base64String
8888

8989
return {
90-
base64: useBase64 ? base64 || lqip : null,
90+
base64: buildLowFiUrl(originalPath, { width, height, aspectRatio: desiredAspectRatio }),
9191
aspectRatio: desiredAspectRatio,
9292
width: Math.round(width),
9393
height: outputHeight,

src/getFluidGatsbyImage.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import getBasicImageProps from './utils/getBasicImageProps'
2-
import buildUrl from './utils/buildImageUrl'
2+
import buildUrl, { buildLowFiUrl } from './utils/buildImageUrl'
33
import { isWebP } from './utils/helpers'
44
import { sizeMultipliersFluid, defaultFluidOptions } from './defaults'
55

@@ -40,13 +40,13 @@ function getFluidGatsbyImage(image, args = {}) {
4040

4141
let sizes = options.sizes || `(max-width: ${maxWidth}px) 100vw, ${maxWidth}px`
4242
let widths = sizeMultipliersFluid
43-
.map(scale => Math.round(maxWidth * scale))
44-
.filter(width => width < dimensions.width)
43+
.map((scale) => Math.round(maxWidth * scale))
44+
.filter((width) => width < dimensions.width)
4545
.concat(dimensions.width)
4646

4747
let initial = { webp: [], base: [] }
4848
let srcSets = widths
49-
.filter(currentWidth => currentWidth < dimensions.width)
49+
.filter((currentWidth) => currentWidth < dimensions.width)
5050
.reduce((acc, currentWidth) => {
5151
let currentHeight = Math.round(currentWidth / desiredAspectRatio)
5252

@@ -87,7 +87,7 @@ function getFluidGatsbyImage(image, args = {}) {
8787
})
8888

8989
return {
90-
base64: useBase64 ? base64 || lqip : null,
90+
base64: buildLowFiUrl(originalPath, { width: maxWidth, height: maxHeight, aspectRatio: desiredAspectRatio }),
9191
aspectRatio: desiredAspectRatio,
9292
src,
9393
srcWebp,

src/utils/buildImageUrl.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,12 @@ function buildImageUrl(originalPath, image) {
3535
return url
3636
}
3737

38+
export function buildLowFiUrl(originalPath, {width, height, aspectRatio }) {
39+
return buildImageUrl(originalPath, {
40+
width: (width / 3).toFixed(0),
41+
height: (height / 3).toFixed(0),
42+
quality: 10
43+
})
44+
}
45+
3846
export default buildImageUrl

src/utils/getBasicImageProps.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function getBasicImageProps(image) {
2323
let originalPath = url.replace(storyblokRegex, '')
2424

2525
let [, , dimensions, , filename] = originalPath.split('/')
26-
let [width, height] = dimensions.split('x').map(num => parseInt(num, 10))
26+
let [width, height] = dimensions.split('x').map((num) => parseInt(num, 10))
2727
let [, extension] = filename.split('.')
2828

2929
let aspectRatio = width / height
@@ -36,4 +36,4 @@ function getBasicImageProps(image) {
3636
}
3737
}
3838

39-
export default getBasicImageProps
39+
export default getBasicImageProps

0 commit comments

Comments
 (0)