2018.10.8-2 • Published 6 years ago

@amory/image v2018.10.8-2

Weekly downloads
-
License
(Apache-2.0 OR MI...
Repository
github
Last release
6 years ago
  • @amory/image

#+begin_quote Simply a different approach than [https://github.com/gatsbyjs/gatsby/tree/v2/packages/gatsby-image] for responsive high-quality optimized images. #+end_quote

** Overview

=@amory/image= is an image processing plugin and React component for Gatsby v2.

Currently macOS-only, however pull requests for other platforms are appreciated.

Key differences from =gatsby-image=:

  • Complete processing pipeline and all dependencies are included
  • Attempts to balance between reasonable file size with maximum quality
  • Multiple compression tools with all configurable options available
  • SQIP and prominent colors proxy images are available as options
  • Multiple images with media query support built-in to React component
  • No intersection observer support, try [https://www.npmjs.com/package/@researchgate/react-intersection-observer]?
  • No support for image filters, such as grayscale, duotone, rotate, etc.
  • Output destination and filenames are completely configurable

** Install

#+begin_src sh npm install --save @amory/image #+end_src

** Example

#+begin_src sh yarn init -y yarn add gatsby@next react react-dom @amory/image mkdir -p src/pages src/images curl -o "src/images/sun.png" \ "http://www.clker.com/cliparts/3/b/1/2/11971486551534036964ivak_Decorative_Sun.svg.hi.png" #+end_src

**** =gatsby-config.js= #+begin_src js module.exports = { "plugins": "@amory/styletron", "@amory/image" } #+end_src

or

#+begin_src js module.exports = { "plugins": "@amory/styletron", { "options": { "src": "src/images" }, "resolve": "@amory/image" } } #+end_src

**** =src/pages/index.js=

#+begin_src js import Img from "@amory/image" import React from "react"

export default ({ data }) =>

export const query = graphql query indexQuery { sun: image(name: {eq: "sun"}) { xs: resize(aspectRatio: "1.618" width: 300) { ... ImageXs } md: resize(aspectRatio: "1.618" width: 600) { ... ImageMd } } } #+end_src

** =Image= Methods

*** =resize=

**** Arguments

  • =aspectRatio= (string, examples: "=1.618=", "=16/9=", or "=21:9=")
  • =cropFocus= (enum, default: =center=)
  • =devicePixelRatios= (array of ints or floats, default: =1, 2=)
  • =height= (int, default: original file height in pixels)
  • =saveDir= (array of strings or variables, default ="/" "img" "relDir" "initName"=)
    • =initName= (original filename without extension)
    • =saveDppx= (output device pixel ratio, e.g. "2x")
    • =relDir= (subdirectories containing original file)
    • Any other string is passed as-is
  • =saveName= (array of strings or variables, default ="initName" "@" "saveDppx" "-" "saveOpts" "." "saveExt"=)
    • =initHash= (original file content digest hash)
    • =initName=
    • =quality= (=quality= argument on some file types)
    • =saveDppx=
    • =saveExt= (output file default extension)
    • =saveHeight= (output file height in pixels)
    • =saveOpts= (unique hash of query arguments)
    • =saveWidth= (output file width in pixels)
    • Any other string is passed as-is
  • =width= (int, default: original file width in pixels)

Original aspect ratio is maintained unless =aspectRatio=, =cropFocus=, =height=, and/or =width= is defined)

**** Fields

  • =height=
  • =width=

**** Fragments

  • =... ImageXl=

#+begin_src graphql fragment ImageXl on ImageResize { height width media(mq: xl) proxy(style: sqip) { srcset type } jpg { srcset type } webp { srcset type } } #+end_src

  • =... ImageLg=

#+begin_src graphql fragment ImageLg on ImageResize { height width media(mq: lg) proxy(style: sqip) { srcset type } jpg { srcset type } webp { srcset type } } #+end_src

  • =... ImageMd=

#+begin_src graphql fragment ImageMd on ImageResize { height width media(mq: md) proxy(style: sqip) { srcset type } jpg { srcset type } webp { srcset type } } #+end_src

  • =... ImageSm=

#+begin_src graphql fragment ImageSm on ImageResize { height width media(mq: sm) proxy(style: sqip) { srcset type } jpg { srcset type } webp { srcset type } } #+end_src

  • =... ImageXs=

#+begin_src graphql fragment ImageXs on ImageResize { height width media(mq: xs) proxy(style: sqip) { srcset type } jpg { srcset type } webp { srcset type } } #+end_src

*** =jpg=

**** Arguments

**** Fields

  • =srcset=
  • =type=

*** =media=

**** Arguments

  • =mq= (enum, media query breakpoint, default: =xs=)

    • =xs= (Fallback image for pages of any width, value: =null=)
    • =sm= (Small image for pages 576px wide and up, value: =(min-width: 576px)=)
    • =md= (Medium image for pages 768px wide and up, value: =(min-width: 768px)=)
    • =lg= (Large image for pages 992px wide and up, value: =(min-width: 992px)=)
    • =xl= (Extra-large image for pages 1200px wide and up, value: =(min-width: 1200px)=)

    Visit 'https://getbootstrap.com/docs/4.1/layout/overview/#responsive-breakpoints' for details.

*** =png=

**** Arguments

  • =actions= (array of tools used to process PNG output, default =zopflipng=)
    • =AdvPNG=
    • =OptiPNG=
    • =Pngcrush=
    • =PNGOUT=
    • =pngquant= (lossy compression tool)
    • =zopflipng=
  • =metadata= (boolean, keep metadata from original file, default: =false=)
  • =quality= (integer, maximum PNG quality, default: =95=)

**** Fields

  • =srcset=
  • =type=

*** =proxy=

**** Arguments

  • =blur= (integer, =sqip= only: GaussianBlur SVG filter value, default: =5=)
  • =mode= (enum, =sqip= only, style of primitives to use, default: =combo=)
  • =numberOfPrimitives= (integer, =sqip= only: number of shapes to use, default: =40=)
  • =palette= (enum, =color= only: array of prominent colors, =Vibrant, Muted=)
  • =style= (enum, default: =lqip=)
    • =color= (extracted prominent color from image)
    • =lqip= (Low Quality Image Placeholder: Blurry bitmap thumbnail image)
    • =sqip= (SVG Image Placeholder: Blurry vector shape-based image)
  • =thumb= (integer, =lqip= only: percentage size of output file, default: =20=)

**** Fields

  • =srcset= (data URI of proxy image)
  • =type= (mime-type of proxy image)

*** =webp=

**** Arguments

  • =lossless= (boolean, encode WebP image losslessly, default: =false=)
  • =metadata= (boolean, keep metadata from original file, default: =false=)
  • =quality= (integer, maximum WebP quality, default: =80=)

**** Fields

  • =srcset=
  • =type=
2018.10.8-2

6 years ago

2018.8.16-1

6 years ago

2018.8.14-1

6 years ago

2018.8.14-0

6 years ago

2018.8.13-6

6 years ago

2018.8.5-1

6 years ago

2018.8.5-0

6 years ago

2018.8.4-6

6 years ago

2018.8.4-5

6 years ago

2018.8.4-4

6 years ago

2018.8.4-3

6 years ago

2018.8.4-2

6 years ago

2018.8.4-1

6 years ago

2018.8.4-0

6 years ago

2018.7.30-0

6 years ago

2018.7.27-7

6 years ago

2018.7.27-6

6 years ago

2018.7.27-5

6 years ago

2018.7.27-4

6 years ago

2018.7.27-3

6 years ago

2018.7.27-2

6 years ago

2018.7.27-1

6 years ago

2018.7.27-0

6 years ago

2018.7.26-10

6 years ago

2018.7.26-9

6 years ago

2018.7.26-8

6 years ago

2018.7.26-7

6 years ago

2018.7.26-6

6 years ago

2018.7.26-5

6 years ago

2018.7.26-4

6 years ago

2018.7.26-3

6 years ago

2018.7.26-2

6 years ago

2018.7.26-1

6 years ago

2018.7.26-0

6 years ago

2018.7.15-1

6 years ago

2018.7.11-8

6 years ago

2018.7.11-7

6 years ago

2018.7.11-6

6 years ago

2018.7.11-5

6 years ago

2018.7.11-4

6 years ago

2018.7.11-3

6 years ago

2018.7.11-2

6 years ago

2018.7.11-1

6 years ago

2018.7.11-0

6 years ago

2018.7.9-2

6 years ago

2018.7.9-1

6 years ago

2018.7.9-0

6 years ago

2018.6.27-2

6 years ago

2018.6.23-0

6 years ago

2018.6.16-0

6 years ago

2018.6.12-5

6 years ago

2018.6.12-4

6 years ago

2018.6.12-3

6 years ago

2018.6.12-2

6 years ago

2018.6.12-1

6 years ago

2018.6.12-0

6 years ago

2018.6.7-2

6 years ago

2018.6.7-1

6 years ago

2018.6.7-0

6 years ago

2018.6.6-10

6 years ago

2018.6.6-9

6 years ago

2018.6.6-8

6 years ago

2018.6.6-7

6 years ago

2018.6.6-6

6 years ago

2018.6.6-5

6 years ago

2018.6.6-4

6 years ago

2018.6.6-3

6 years ago

2018.6.6-2

6 years ago

2018.6.6-1

6 years ago

2018.6.6-0

6 years ago

2018.6.3-0

6 years ago

2018.6.1-1

6 years ago

2018.6.1-0

6 years ago

2018.5.31-1

6 years ago

2018.5.31-0

6 years ago

2018.5.30-0

6 years ago

2018.5.29-5

6 years ago

2018.5.29-4

6 years ago

2018.5.29-3

6 years ago

2018.5.29-2

6 years ago

2018.5.29-1

6 years ago

2018.5.29-0

6 years ago

2018.5.28-1

6 years ago

2018.5.28-0

6 years ago

2018.5.25-3

6 years ago

2018.5.25-2

6 years ago

2018.5.25-1

6 years ago

2018.5.25-0

6 years ago

2018.5.24-1

6 years ago

2018.5.24-0

6 years ago

2018.5.23-7

6 years ago

2018.5.23-6

6 years ago

2018.5.23-5

6 years ago

2018.5.23-4

6 years ago

2018.5.23-3

6 years ago

2018.5.23-2

6 years ago

2018.5.23-1

6 years ago

2018.5.23-0

6 years ago

2018.5.21-9

6 years ago

2018.5.21-8

6 years ago

2018.5.21-7

6 years ago

2018.5.21-6

6 years ago

2018.5.21-5

6 years ago

2018.5.21-4

6 years ago

2018.5.21-3

6 years ago

2018.5.21-2

6 years ago

2018.5.21-1

6 years ago

2018.5.21-0

6 years ago

2018.5.20-5

6 years ago

2018.5.20-4

6 years ago

2018.5.20-3

6 years ago

2018.5.20-2

6 years ago

2018.5.20-1

6 years ago

2018.5.20-0

6 years ago

2018.5.19-3

6 years ago

2018.5.19-2

6 years ago

2018.5.19-1

6 years ago

2018.5.19-0

6 years ago

2018.5.18-2

6 years ago

2018.5.18-1

6 years ago

2018.5.18-0

6 years ago

2018.5.17-1

6 years ago

2018.5.17-0

6 years ago

2018.5.16-3

6 years ago

2018.5.16-2

6 years ago

2018.5.16-1

6 years ago

2018.5.16-0

6 years ago

2018.5.15-4

6 years ago

2018.5.15-3

6 years ago

2018.5.15-2

6 years ago

2018.5.15-1

6 years ago

2018.5.15-0

6 years ago

2018.5.14-5

6 years ago

2018.5.14-4

6 years ago

2018.5.14-3

6 years ago

2018.5.14-2

6 years ago

2018.5.14-1

6 years ago

2018.5.14-0

6 years ago

2018.5.13-6

6 years ago

2018.5.13-5

6 years ago

2018.5.13-4

6 years ago

2018.5.13-3

6 years ago

2018.5.13-2

6 years ago

2018.5.13-1

6 years ago

2018.5.13-0

6 years ago

2018.5.12-0

6 years ago

2018.5.11-7

6 years ago

2018.5.11-6

6 years ago

2018.5.11-5

6 years ago

2018.5.11-4

6 years ago

2018.5.11-3

6 years ago

2018.5.11-2

6 years ago

2018.5.10-1

6 years ago

2018.5.10-0

6 years ago