GithubHelp home page GithubHelp logo

weixin / gulp-lazyimagecss Goto Github PK

View Code? Open in Web Editor NEW
34.0 7.0 8.0 43 KB

自动生成图片CSS属性,如:width & height 等

Home Page: https://www.npmjs.com/package/gulp-lazyimagecss

License: MIT License

JavaScript 78.09% CSS 21.91%

gulp-lazyimagecss's Introduction

gulp-lazyimagecss NPM Version

Build Status Win Build status dependencies NPM Downloads

Join the chat at https://gitter.im/weixin/gulp-lazyimagecss TmT Name License

Be lazy, add images's CSS automatically, like width & height and more.
Save time, make money.

NPM Home Page: https://www.npmjs.com/package/gulp-lazyimagecss

中文(zh_CN) 说明文档 →

Install

Install with NPM:

npm install gulp-lazyimagecss --save

Usage

gulpfile.js

var lazyimagecss = require('gulp-lazyimagecss');

gulp.src(paths.src.less)
    .pipe(less())
    .pipe(lazyimagecss())
    .pipe(gulp.dest(paths.src.css));
        	

Options
Set CSS which you wish to be added automatically.

options = lodash.extend({
    width: true, // Output width in CSS
    height: true, // Output height in CSS
    backgroundSize: true, // Output background-size in CSS
    imagePath: [] // Set image path to be worked (e.g. `['../slice','../img']`)
}, options);

Result

CSS In

.bg-test {
	background: url(../img/bg.png);
	background-repeat: no-repeat;
}
.icon-test {
	background-image: url(../slice/test.png);
}
.icon-test-retina {
	background-image: url(../slice/[email protected]);
}

CSS Out

.bg-test {
	background: url(../img/bg.png);
	background-repeat: no-repeat;
	width: 1100px;
	height: 300px;
}
.icon-test {
	background-image: url(../slice/test.png); // test.png - 32x32
	width: 32px;
    height: 32px;
}
.icon-test-retina {
	background-image: url(../slice/[email protected]); // [email protected] - 64x64
	width: 32px;
    height: 32px;
    background-size: 32px;
}

Tips: Use PostCSS with CSS Out if needed.

Notes

  • CSS property generating will be ignored if any of those width / height / background-size already set.
  • Both background-image: url() and background: url() can be detected successfully.
  • Get image size from HEX data from file buffer via fast-image-size, more fast now.
  • Detect PNG & JPG based on file signatures.
  • No minimum image buffer size limited now /fast-image-size/pull/5.

Contributing

This repo is build and maintained by TmT Team.
If you get any bugs or feature requests, please open a new Issue or send us Pull Request, Thank you for your contributions.

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.