Git Product home page Git Product logo

kirbytext-image-plugin's Introduction

Kirbytext Image Plugin

Prevents reflow, adds lazy loading (requires lazysizes), and srcset to each image added with an (image: …) tag. The default width is 100%, height set to "auto".

Overrides (image: …) KirbyTag located in kirby/config/tags.php. More info on overriding default tags: getkirby.com/docs/reference/plugins/extensions/kirbytags#overriding-default-kirbytags.

Output

<div class="responsive-image">
  <div class="placeholder" style="padding-bottom: 100%"></div>
  <img class="lazy lazyautosizes lazyloaded" data-sizes="auto" data-src="http://example.test/image.jpg" data-srcset="http://example.test/image-400x.jpg 400w, http://example.test/image-800x.jpg 800w, http://example.test/image-1020x.jpg 1020w, http://example.test/image-2040x.jpg 2040w" alt="Image" width="100%" height="auto" sizes="377px" srcset="http://example.test/image-400x.jpg 400w, http://example.test/image-800x.jpg 800w, http://example.test/image-1020x.jpg 1020w, http://example.test/image-2040x.jpg 2040w" src="http://example.test/image.jpg">
  <noscript>
    <img src='http://example.test/image.jpg' alt='Image' width='100%' height='auto'>
  </noscript>
</div>

Setup

  1. Add lazysizes to the project
  2. Download and copy this repository to /site/plugins

Use in a template

<div class='responsive-image'>
  <div class='placeholder' style='padding-bottom: <?= number_format(100 / $page->image()->ratio(), 5, '.', '') ?>%'></div>
  <img class='lazy lazyload' data-sizes='auto'
      data-src='<?= $page->image()->url() ?>'
      data-srcset='<?= $page->image()->srcset([400, 800, 1020, 2040]) ?>'
      alt='<?= $page->title()->html() ?>'
      width='100%' height='auto'/>
  <noscript>
    <img src='<?= $page->image()->url() ?>' alt='<?= $page->title()->html() ?>' width='100%' height='auto' />
  </noscript>
</div>

kirbytext-image-plugin's People

Contributors

stuymedova avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.