All Projects → mgsod → imgZip

mgsod / imgZip

Licence: MIT license
js压缩图片,转blod流.上传

Programming Languages

typescript
32286 projects
HTML
75241 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to imgZip

ZipArchive
A single-class pure VB6 library for zip with ASM speed
Stars: ✭ 38 (+52%)
Mutual labels:  zip, compress
minizip-asm.js
Minizip in javascript. Work with password. Demo:
Stars: ✭ 38 (+52%)
Mutual labels:  zip, compress
pclzip-doc-zh-cn
PHP 库 PclZip 的简体中文翻译文档(zh-cn translation for PHP lib: PclZip)
Stars: ✭ 25 (+0%)
Mutual labels:  zip, compress
lzbase62
LZ77(LZSS) based compression algorithm in base62 for JavaScript.
Stars: ✭ 38 (+52%)
Mutual labels:  zip, compress
QArchive
Async C++ Cross-Platform library that modernizes libarchive using Qt5 🚀. Simply extracts 7z 🍔, Tarballs 🎱 and other supported formats by libarchive. ❤️
Stars: ✭ 66 (+164%)
Mutual labels:  zip, compress
Backdoor
A backdoor that runs on Linux and Windows
Stars: ✭ 36 (+44%)
Mutual labels:  zip
miniz-cpp
A cross-platform header-only C++14 library for reading and writing ZIP files
Stars: ✭ 117 (+368%)
Mutual labels:  zip
pyas2-lib
AS2 Library for building and parsing Messages and MDNs
Stars: ✭ 33 (+32%)
Mutual labels:  compress
qlZipInfo
MacOSX QuickLook Generator for zip, jar, tar, tar.gz (.tgz), tar.bz2 (.tbz2/.tbz), tar.Z. xar (.xar, .pkg), debian (.deb), RedHat Package Manager (.rpm), 7zip (.7z), xz, Microsoft cabinet (.cab), gzip (.gz), lha, BinHex 4.0 (.hqx), and Stuffit (.sit) archives, and ISO9660 images
Stars: ✭ 47 (+88%)
Mutual labels:  zip
ak-cli
🔖 Collection of useful cli commands
Stars: ✭ 39 (+56%)
Mutual labels:  zip
photo-magician
🎨 provide some common image process apis with canvas
Stars: ✭ 12 (-52%)
Mutual labels:  compress
Golang-Files-Preview
Golang 文件预览支持 office\pdf\cad\achieve\txt\image\video files
Stars: ✭ 53 (+112%)
Mutual labels:  zip
tinypng-free
Use the upload api of tinypng's homeage to compress images
Stars: ✭ 29 (+16%)
Mutual labels:  compress
CodeProject
Common code for unity project develop.
Stars: ✭ 28 (+12%)
Mutual labels:  compress
VszLib
7-zip VB6 Helper
Stars: ✭ 35 (+40%)
Mutual labels:  zip
zipit
Decentralized or self-hosted encryption archives that work on any internet device.
Stars: ✭ 14 (-44%)
Mutual labels:  zip
zip install
Mit diesem AddOn kannst du gezippte AddOns oder PlugIns einfach im Backend hochladen und installieren.
Stars: ✭ 32 (+28%)
Mutual labels:  zip
ftpConnect
A simple and robust dart FTP Client Library to interact with FTP Servers with possibility of zip and unzip files.
Stars: ✭ 43 (+72%)
Mutual labels:  zip
vim-rzip
Extends zip.vim to browse and write nested zip files
Stars: ✭ 22 (-12%)
Mutual labels:  zip
unarr
A decompression library for rar, tar, zip and 7z archives
Stars: ✭ 35 (+40%)
Mutual labels:  zip

imgZip

图片压缩插件

Demo示例

图片压缩

安装

npm

 npm i imgzip

script

<script src="https://unpkg.com/[email protected]/dist/index.min.js"></script>

@2.0.8为固定版本,可自行调整

使用方法

2.x版本(支持ts)

import imgzip from "imgzip";

export default {
  name: "App",
  mounted() {
    // 监听选择文件
    document.getElementById("file").onchange = function () {
      // @2.x版本后采用 class Api。所以需要 new 一个 imgZip 对象
      let compress = new imgzip({ quality: 0.5 });
      // 调用图片压缩
      compress.photoCompress(this.files[0], function (base64) {
        // document.getElementById('img').src = base64  //预览图片
        // 转 blob 流上传 convertBase64UrlToBlob函数为 imgzip 的静态函数
        let blob = imgzip.convertBase64UrlToBlob(base64);
        let formData = new FormData();
        formData.append("file", blob, "file_" + Date.parse(new Date()) + ".jpg"); // 文件对象
        // 上传操作....
      });
    };
  },
};

函数说明

@2.x版本后改用class api, 原photoCompress函数中传入的options参数改为实例化imgzip时传入。

  • new imgZip(options)
参数 说明 是否必须 默认值
options.width 图片宽度 图片原始宽度
options.height 图片高度 图片原始高度
options.quality 图片质量 0.7
  • photoCompress(图片压缩函数) 无返回值
参数 说明 是否必须 默认值
file 文件对象(Blod) -
callback 压缩后回调函数,回调参数返回压缩后的base64编码 -

1.x版本(不支持ts)

import imgzip from "imgzip";

export default {
  name: "App",
  mounted() {
    // 监听选择文件
    document.getElementById("file").onchange = function () {
      // 调用图片压缩
      imgzip.photoCompress(this.files[0], {}, function (base64) {
        // document.getElementById('img').src = base64  //预览图片
        // 转 blob 流上传
        let blob = imgzip.convertBase64UrlToBlob(base64);
        let formData = new FormData();
        formData.append("file", blob, "file_" + Date.parse(new Date()) + ".jpg"); // 文件对象
        // 上传操作....
      });
    };
  },
};

函数说明

  • photoCompress(图片压缩函数)
参数 说明 是否必须 默认值
file 文件对象(Blod) -
options 压缩参数(宽/高/质量) {width:图片高度,height:图片宽高比,quality:0.7}
callback 压缩后回调函数,回调参数返回压缩后的base64编码 -
  • convertBase64UrlToBlob(base64编码转blod流) 1.x版本和2.x版本均为imgzip的静态函数
参数 说明 是否必须 默认值 返回值
base64 图片base64编码 - Blod
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].