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

html-image-compress

v1.1.0

Published

html图片压缩,兼容移动端ios,android,wechat

Downloads

30

Readme

imageCompress

html5 图片 压缩

1、如何安装

 npm install --save-dev html-image-compress

2、如何使用

<input id="file" type="file" accept="image/*" />
// 模块默认输出 图片压缩的构造器
import HtmlImageCompress from 'html-image-compress'

document.querySelector('#file').addEventListener('change', function () {
  var htmlImageCompress = new HtmlImageCompress(this.files[0],{quality:0.7})
  htmlImageCompress.then(function(result){
    // 成功后执行
      var file = result.file; // 压缩后的图片文件(file)对象
      var fileSize = result.fileSize // 压缩后的图片文件(file)大小
      var base64 = result.base64; // 压缩后的base64图片
      var origin = result.origin; // 压缩前的图片文件(file)对象
  })
  .catch(function (err) {
     // 处理失败会执行
  })

});

3、参数

new HtmlImageCompress(file, [options]);
  • file 通过 input:file 得到的文件

  • [options] 这个参数允许忽略

    • width {Number} 图片最大不超过的宽度,默认为原图宽度,高度不设时会适应宽度。
    • height {Number} 同上
    • quality {Number} 图片压缩质量,取值 0 - 1,默认为0.7  * imageType {String} 图片类型 ,默认 'image/jpeg'

4、返回结果

  • 返回值是一个promise对象 then(result)
    • result.file 压缩后的file对象
    • result.fileLen 生成后的图片的大小,后端可以通过此值来校验是否传输完整
    • result.base64 生成后的图片base64,后端可以处理此字符串为图片,也直接用于img.src = base64
    • result.base64Len 生成后的base64的大小,后端可以通过此值来校验是否传输完整 (如果采用base64上传方式)
    • result.origin 也就是原始的file对象,里面存了一些原始文件的信息,例如大小,日期等。