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

[Ready 4 Review] SQIP - Vectorized primitive image previews #4205

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
033faad
first working version with Contentful assets only
Feb 23, 2018
7660c4e
add readme
Feb 23, 2018
5781b9c
respect width, height, aspect ratio, cropping, resize focus and backg…
Feb 23, 2018
f7f05da
add support for gatsby-transformer-sharp
Feb 23, 2018
b72921b
integrate in gatsbygram
axe312ger Feb 23, 2018
b6cdeab
avoid useless regeneration cus contentDigest changes
axe312ger Feb 25, 2018
d571ba8
proper way to get absolute path to ImageSharp nodes
axe312ger Feb 25, 2018
423ed1a
queue preview generation and cache results on disk
axe312ger Feb 25, 2018
d11370b
upgrade to latest node-sqip to get rid of the GoLang dependency
Mar 2, 2018
4550f94
replace custom svg data uri function with package
Mar 2, 2018
19c33d0
prepare images via sharp plugin and allow sharp transformations
axe312ger Mar 3, 2018
a386a12
load cached svg properly from disk
axe312ger Mar 3, 2018
64a6dd2
fix queue resolving to early
axe312ger Mar 3, 2018
6e8f3a4
set contentful images to 400px
axe312ger Mar 3, 2018
84ebf42
implement new sharp transformation awareness feature
axe312ger Mar 3, 2018
f2ffe45
WIP - extract generation and write first pseudo test
axe312ger Mar 3, 2018
5c11f36
fix styling for gatsbygram post detail
axe312ger Mar 3, 2018
48006eb
finalize unit tests for actual sqip implementation
axe312ger Apr 29, 2018
f058965
use 256px input image width to match sqip/primitive default
axe312ger Apr 29, 2018
365f36c
add using-sqip example page
axe312ger Apr 30, 2018
36fc041
some cleanup
axe312ger Apr 30, 2018
f8b4caa
clean up example and enhance polaroid effect
axe312ger Apr 30, 2018
a439dee
fix using-sqip dependency
axe312ger Apr 30, 2018
3fdca72
remove base64 since it was not implemented and is bad for compression
axe312ger Apr 30, 2018
fb22bcb
remove sqip from gatsbygram example
axe312ger Apr 30, 2018
b551857
simplify tests
axe312ger Apr 30, 2018
df6c807
Small change to trigger build
KyleAMathews May 1, 2018
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
8 changes: 8 additions & 0 deletions examples/using-sqip/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"env": {
"browser": true
},
"globals": {
"graphql": false
}
}
8 changes: 8 additions & 0 deletions examples/using-sqip/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Project dependencies
.cache
node_modules
yarn-error.log

# Build directory
/public
.DS_Store
5 changes: 5 additions & 0 deletions examples/using-sqip/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "es5"
}
25 changes: 25 additions & 0 deletions examples/using-sqip/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
siteMetadata: {
title: `Gatsby SQIP Example`,
},
plugins: [
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images/`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `background`,
path: `${__dirname}/src/background/`,
},
},
`gatsby-image`,
`gatsby-plugin-sharp`,
`gatsby-transformer-sharp`,
`gatsby-transformer-sqip`,
],
}
25 changes: 25 additions & 0 deletions examples/using-sqip/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "using-sqip",
"description": "Gatsby example site using the sqip transformer plugin",
"version": "1.0.0",
"author": "Benedikt Rötsch <info@benedikt-roetsch.de>",
"dependencies": {
"gatsby": "^1.9.247",
"gatsby-image": "^1.0.48",
"gatsby-plugin-sharp": "^1.6.43",
"gatsby-source-filesystem": "^1.5.34",
"gatsby-transformer-sharp": "^1.6.23",
"gatsby-transformer-sqip": "*"
},
"keywords": ["gatsby"],
"license": "MIT",
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write 'src/**/*.js'",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"prettier": "^1.12.0"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 116 additions & 0 deletions examples/using-sqip/src/components/polaroid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import React from 'react'
import PropTypes from 'prop-types'

import Image from 'gatsby-image'

// Styling based on https://codepen.io/havardob/pen/ZOOmMe

const data = {
'alisa-anton-166247-unsplash-2000px': {
style: { left: `6vw`, bottom: `6vw` },
author: `Alisa Anton`,
url: `https://unsplash.com/photos/ukxAK0c2FqM`,
},
'anthony-esau-173126-unsplash-2000px': {
style: { left: `30vw`, bottom: `12vw` },
author: `Anthony Esau`,
url: `https://unsplash.com/photos/N2zk9yXjmLA`,
},
'beth-solano-313648-unsplash-2000px': {
style: { left: `39vw`, top: `3vw` },
author: `Beth Solando`,
url: `https://unsplash.com/photos/VGkn9ENxLXM`,
},
'desmond-simon-412494-unsplash-2000px': {
style: { right: `5vw`, bottom: `5vw` },
author: `Desmond Simon`,
url: `https://unsplash.com/photos/HhOo98Iygps`,
},
'igor-ovsyannykov-307432-unsplash-2000px': {
style: { right: `27vw`, bottom: `3vw` },
author: `Igor Ovsyannykov`,
url: `https://unsplash.com/photos/uzd2UEDdQJ8`,
},
'quino-al-101314-unsplash-2000px': {
style: { right: `28vw`, bottom: `27vw` },
author: `Quino Al`,
url: `https://unsplash.com/photos/vBxlL1xpSdc`,
},
'samuel-zeller-16570-unsplash-2000px': {
style: { right: `16vw`, top: `2vw` },
author: `Samuel Zeller`,
url: `https://unsplash.com/photos/CwkiN6_qpDI`,
},
'tyler-lastovich-205631-unsplash-2000px': {
style: { right: `3vw`, top: `14vw` },
author: `Tyler Lastovich`,
url: `https://unsplash.com/photos/DMJUIGRO_1M`,
},
}

function generateStyle(imageData) {
const rotation = Math.floor(Math.random() * 26) - 13
return {
boxSizing: `content-box`,

display: `block`,
position: `absolute`,

width: `18vw`,

padding: `0.8vw 0.4vw 0`,
background: `linear-gradient(120deg, #fff, #eee 60%)`,

color: `inherit`,

boxShadow: `2px 2px 7px 0px rgba(0,0,0,0.4), rgba(0, 0, 0, 0.1) 1px 1px 3px 0px inset`,
transform: `rotate(${rotation}deg)`,

...imageData.style,
}
}

const Polaroid = ({ image }) => {
const imageData = data[image.name]

return (
<a
href={imageData.url}
title={`by ${imageData.author}`}
style={generateStyle(imageData)}
>
<div style={{ position: `relative` }}>
<Image
sizes={{
...image.childImageSharp.sizes,
base64: image.childImageSharp.sqip.dataURI,
}}
/>
<div
style={{
position: `absolute`,
top: 0,
left: 0,
background: `linear-gradient(120deg, rgba(255, 255, 255, 0.5), transparent 60%, rgba(0, 0, 0, 0.4) 99%)`,
boxShadow: `inset 4px 5px 10px 0 rgba(0,0,0,0.05)`,
width: `100%`,
height: `100%`
}}
/>
</div>
<div
style={{
lineHeight: `4vw`,
textAlign: `center`,
fontSize: `1.6vw`,
}}
>{`📷 ${imageData.author}`}</div>
</a>
)
}

Polaroid.propTypes = {
image: PropTypes.object,
}

export default Polaroid
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading