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

ls-compressimage

v1.0.1

Published

图片处理,压缩 转换格式 自定义图片大小 限制文件大小 自定义图片名 文件类型

Downloads

3

Readme

Installation

npm i ls-compressimage --save

Use

import compressImage from 'ls-compressimage'
new compressImage({
        res: data.imgTime, // 必选 资源
        justConversion: true, // 可选 声明了此字段说明只进行格式转换 res requestType responseType callback必填,其他随意
        width: 500, // 可选(justConversion存在可不选) (默认图片自身宽度,建议自定义) 压缩后图片宽度
        // height: image.height,//可选 (默认 自定义图片宽度/原生图片宽度*原生图片高度) 压缩后图片高度
        quality: 0.2, // 可选 (默认0.3) 压缩层级质量(0<quality<1)越大压缩越快 图片质量跨度相对低 越小则相反
        size: 200, // 必选(justConversion存在可不选) 压缩后图片大小 单位k
        requestType: 'base64', // 必选 传入文件类别 base64 | file | blob
        responseType: 'base64', // 必选 返回文件类别 base64 | file | blob
        imgType: 'image/jpeg', // 可选 (默认原生文件类型) 返回文件对象的文件类型
        fileName: 'ysl', // 如果responseType的类型为file和非justConversion 此选项可选 返回文件对象的文件名
        callback: (result) => {
          if (result === null) {
            alert('图片处理异常')
            return
          }
          this.params.mainImagePath = result
        } // 回调函数 返回处理后文件 如果为null 表示文件处理不了(原因 少了参数 参数不合法))
      })

###Tip 参数requestType 必须对应 参数res的形态,否则处理可能异常 size结果为 <= size 如quality过小,则至多压缩25次,建议0.1~0.3 当然这个自己把握 width建议设置 手机拍照宽度都好几千 按比例压缩效果反而没自定义width好 ####---end