npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-picture-html

v1.0.2

Published

Replaces <img> tag with <picture> <source>( .webp, .avif,.., data-src/-srcset"data:image..")<img> gulp in HTML files.

Downloads

19

Readme

gulp-picture-html

Gulp extension, replace html element <img> to <picture> with gulp-picture-html

Install

$ npm install gulp-picture-html --save-dev

Usage

Use this into your gulpfile.js:

Basic

const gulp = require('gulp')
const pictureHTML = require("gulp-picture-html")

function html() {
  return src('source/*.html')
    .pipe(pictureHTML())
    .pipe(gulp.dest('dist/'))
}

exports.html = html;

Custom plugin options

// …
.pipe(pictureHTML(      
  options: // below default
  {
    extensions : ['.png','.jpg'], // image file extensions for which we create 'picture'
    source : ['.avif', '.webp'], // create 'source' with these formats   
    noPicture : ['no-sourse'],  // if we find this class for the 'img' tag, then we don't create a 'picture' (multiple classes can be set)
    noPictureDel : false // if 'true' remove classes for 'img' tag given in 'noSource:[]'
  }
))
//...

Example

// Input
<!-- Does not change the commented out 'img' tag
  <img src="img/image.jpg" alt="image"> -->
<img src="img/image.jpg" alt="image">
<!-- Doesn't change the 'img' tag because there is a 'no-picture' class -->
<!-- Setting 'noSourceDel = true' will remove the given class(s) in 'noSource:[]' -->
<img class="no-picture" src="img/image.jpg" alt="image">
<!-- Converts all formats found in 'srcset' -->
<img src="img/image.jpeg" srcset="img/image-2.PNG 2x, img/image-200.png 200w" width="500" height="300">
<!-- For lazy loading with JS, finding 'data-src' creates 'src' and 'srcset' c 'data:image/png;...' -->
<img data-src="img/verstka.jpeg" data-srcset="img/medium.PNG 2x, img/demo-200px.png 200w" width="500" height="300">
// Output
<!-- Does not change the commented out 'img' tag
  <img src="img/image.jpg" alt="image"> -->
<picture>
    <source srcset="img/image.avif" type="image/avif">
    <source srcset="img/image.webp" type="image/webp">
    <img src="img/image.jpg" alt="image">
</picture>
<!-- Doesn't change the 'img' tag because there is a 'no-picture' class -->
<img class="no-picture" src="img/image.jpg" alt="image">
<!-- Setting 'noSourceDel = true' will remove the given class(s) in 'noSource:[]' -->
<img src="img/image.jpg" alt="image">
<!-- Converts all formats found in 'srcset' -->
<picture>
  <source srcset="img/image.avif, img/image-2.avif 2x, img/image-200.avif 200w" type="image/avif">  
  <source srcset="img/image.webp, img/image-2.webp 2x, img/image-200.webp 200w" type="image/webp">  
  <img src="img/image.jpeg" srcset="img/image-2.PNG 2x, img/image-200.png 200w" width="500" height="300">
</picture>
<!-- For lazy loading with JS: finding 'data-src' creates 'src' and 'srcset' c 'data:image/png;...' -->
<picture>
  <source data-srcset="img/verstka.avif, img/medium.avif 2x, img/demo-200px.avif 200w" srcset="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" type="image/avif">  
  <source data-srcset="img/verstka.webp, img/medium.webp 2x, img/demo-200px.webp 200w" srcset="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" type="image/webp">  
  <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" data-src="img/verstka.jpeg" data-srcset="img/medium.PNG 2x, img/demo-200px.png 200w" width="500" height="300">
</picture>

The picture element

For now, you can still use the format in it's almost complete glory with the native <picture> element in HTML. Why, you may ask? Well, the <picture> element allows progressive support. You can simply drop all image files in the order in which you want to load them. Your visitors' browsers load only one image at a time, which reduces the load on the server. Besides, you don't need a script to process multiple images. Currently 97% of browsers support the picture element

Does not download more than one image at a time

Native support for selecting the most appropriate image

97% browser support and automatic fallback

Getting this implemented is easy and straightforward