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

isomorphic-image-compress

v0.1.7

Published

html5 Img Compress

Downloads

3

Readme

demo

http://mhbseal.com/demo/html5/html5ImgCompress/demo/index.html

usage

1.dist目录下文件放入project中(这里采用的是异步加载兼容js,chunk012为处理hack的js,不能删除)
2.引入主文件html5ImgCompress.min.js(源码采用UMD格式),所以可以用以下几种方式引入
1)全局

<script src="/dist/html5ImgCompress.min.js"></script>
<script>new html5ImgCompress(...)</script>

2)amd

require('/dist/html5ImgCompress.min.js', function(html5ImgCompress) {...});

3)commonjs

var html5ImgCompress = require('/dist/html5ImgCompress.min.js');

3.代码如下

<input type="file" />
<script>
  document.getElementsByTagName('input')[0].addEventListener("change", function(e) {
    new html5ImgCompress(e.target.files[0], {
      before: function(file) {
        console.log('压缩前...');
        // 这里一般是对file进行filter,例如用file.type.indexOf('image') > -1来检验是否是图片
        // 如果为非图片,则return false放弃压缩(不执行后续done、fail、complate),并相应提示
      },
      done: function (file, base64) {
        console.log('压缩成功...');
        // ajax和服务器通信上传base64图片等操作
      },
      fail: function(file) {
        console.log('压缩失败...');
      },
      complate: function(file) {
        console.log('压缩完成...');
      },
      notSupport: function(file) {
        console.log('浏览器不支持!')
        // 不支持操作,例如PC在这里可以采用swfupload上传
      }
    });
  }, false)
</script>

4.参数说明

new html5ImgCompress(file, options);

@param {file} 上传文件
@param {object} options选项
  - maxWidth {number} 最大宽度(如果最大高宽同时存在则根据原图的高宽比例来计算以哪个为准),默认值1000
  - maxHeight {number} 最大高度,默认值1000
  - quality {number} 质量等级(类似PS保存事的质量等级,并不是压缩比例),取值范围 0-1,默认值0.6
  - before {function} 压缩前handler
    - param {file} 原始上传文件
    - return {boolean} 是否放弃,返回false放弃压缩
  - done {function} 成功handler
    - param {string} 生成的base64图片
    - param {file} 原始上传文件
  - fail {function} 失败handler
    - param {file} 原始上传文件
  - complate {function} 完成handler
    - param {file} 原始上传文件
  - notSupport {function} 浏览器不支持handler
    - param {file} 原始上传文件

hack

1.图片方向处理
2.安卓微信压缩问题hack
3.IOS6/7压缩扭曲
4.多张上传(如果浏览器支持)