0.2.2 • Published 5 years ago

saber-plugin-image v0.2.2

Weekly downloads
6
License
MIT
Repository
-
Last release
5 years ago

saber-plugin-image

Allows the generation of responsive images (srcset included), lazy-loading and all that good stuff.

Install

yarn add saber-plugin-image

Usage

In your saber-config.yml:

plugins:
  - resolve: saber-plugin-image
    options:
      sizes:
        - 1000
        - 800
        - 500
      placeholder: true
      blendIn: true

Use it, either in Vue or Markdown!

<saber-image
  src="./waifu.jpg"
  :lazy="{
    placeholder: true,
    lazyLoad: true,
    blendIn: true
  }"
/>

Please note that responsive image generation only works with local images. You can use <saber-image> with non-local images to get lazy-loading though.

Options

These options can be passed either in the Saber configuration or to each <saber-image> individually by using the lazy prop. The Saber configuration additionally accepts all Vue Lazyload constructor and Responsive loader options.

KeyDescriptionDefaultType
lazyLoadTurn lazy loading off or on.trueBoolean
placeholderDisplay a generated placeholder while the image is loading.trueBoolean
blendInRequires placeholder to be enabled. Smoothly blends in the loaded image once loaded. You can also pass the transition duration in milliseconds instead of a boolean.Boolean | Integer
markdownImagesTransforms ![Markdown](./images.png) into <saber-image>. You can pass options via the query-string, e. g. image.png?blendIn=true&sizes[]=100,sizes[]=200trueBoolean
qualityJPEG compression quality.85Integer
sizesImages will be downscaled to the specified widths.original image widthArray<Integer>

If you don't like the blendIn loading transition, you can create your own ones, like this fade-in transition:

img {
  transition: opacity 0.5s;
}

img[lazy='loading'] {
  opacity: 0;
}

img[lazy='loaded'] {
  opacity: 1;
}

License

MIT.