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

image-file-convert

v0.0.2

Published

> image util to handle image file, canvas/image/blob/file translate

Downloads

2

Readme

ImageFileConvert

image util to handle image file, canvas/image/blob/file translate

demo

USAGE

copy dist imageFileConvert.umd.js for usage

USE NPM

npm i image-file-convert

import ImageFileConvert from 'image-file-convert'
<input type="file" accept="image/*" onchange="fileChange(event)">
<script src="../dist/imageFileConvert.umd.js"></script>
<script>
function fileChange(ev) {
  let file = ev.target.files[0];
  ImageFileConvert.getImageFileData(file, { width: 600, height: 800, cover: false }).then(({ blob, base64 }) => {
    let img = ImageFileConvert.blobToImage(blob);
    img.style.width = '300px';
    console.log(blob, base64.length)
    document.body.appendChild(img);
  });
}
</script>

API

getImageFileData(file, option);

get image file input data, can compress size with option with and height

| 参数 | 类型 | 说明 | | --- | --- | --- | | file | file type | 文件类型 | | option | object | 配置项 | | | width | 宽度 | | | height | 高度 | | | cover | 是否覆盖整个区域,默认false |

function fileChange(ev) {
  let file = ev.target.files[0];
  ImageFileConvert.getImageFileData(file, { width: 300, height: 400, cover: true }).then(blob => {
    let img = ImageFileConvert.blobToImage(blob);
    document.body.appendChild(img);
  })
}

blobToImage(blob)

blob translate to image, use for ImageFileData() result

| 参数 | 类型 | 说明 | | --- | --- | --- | | blob | blob | 二进制文件 |

let img = ImageFileConvert.blobToImage(blob);

fileToCanvas(file, option);

file translate to canvas and image, get canvas and image

| 参数 | 类型 | 说明 | | --- | --- | --- | | file | file type | 文件类型 | | option | object | 配置项 | | | width | 宽度 | | | height | 高度 | | | cover | 是否覆盖整个区域,默认false |

ImageFileConvert.fileToCanvas(file, { width: 400, height: 400 }).then(({ canvas, image }) => {
  document.body.appendChild(canvas);
})

fileToImage(file);

file translate to image

| 参数 | 类型 | 说明 | | --- | --- | --- | | file | file type | 文件类型 |

ImageFileConvert.fileToImage(file).then(img => {
    document.body.appendChild(img);
})

imageToCanvas(img);

image translate to canvas

| 参数 | 类型 | 说明 | | --- | --- | --- | | img | image element | 图片 |

let canvas = ImageFileConvert.imageToCanvas(img);

canvasToImage(canvas);

canvas tranlate to image, return promise

| 参数 | 类型 | 说明 | | --- | --- | --- | | canvas | canvas | canvas |

ImageFileConvert.canvasToImage(cvs, 'image/png').then(canvas => {
  document.body.append(canvas);
})

canvasToFile(canvas);

canvas translate to file

let file = ImageFileConvert.canvasToFile(cvs);

canvasToBase64(canvas, type = 'image/png', encoderOptions = '0.92');

canvas to base64

let base64 = ImageFileConvert.canvasToBase64(cvs);

imageToBase64(img);

image translate to base64

let base64 = ImageFileConvert.imageToBase64(img);

rotate(canvas, image, degree);

rotate image by canvas and return canvas

| 参数 | 类型 | 说明 | | --- | --- | --- | | canvas | canvas | 需要绘制的canvs | | image | img | img元素 | | degree | int | 角度 |

ImageFileConvert.rotate(cvs, img, degree);