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

photo-magician

v0.3.0

Published

Provide some common image process apis with canvas

Downloads

215

Readme

photo-magician

npm npm version jest

:art: Provide some common image process apis with canvas

React Version

Installation

using yarn :

yarn add photo-magician

using npm :

npm install photo-magician --save

using in the browser :

<script src="photoMagician.min.js"></script>
<script>
    const magician = new photoMagician()
    magician.toBase64Url({cover:"YOUR_IMG_URL"})
</script>

Screenshots

https://github.com/lijinke666/photo-magician/bolb/master/assets/screenshot.png

Example

https://lijinke666.github.io/photo-magician/

Usage

ES6

import photoMagician from "photo-magician";
const magician = new photoMagician();

magician.toBase64Url({ cover: "YOUR_IMG_URL" });

No ES6

const photoMagician = require("photo-magician");
const magician = new photoMagician();

magician.toBase64Url({ cover: "YOUR_IMG_URL" });

set config

// set out put image data quality  [ 0 - 1 ]

magician.setConfig({
  imageQuality: 0.4
});

Return to the promise

//use ES6
magician
  .toBase64Url({
    cover: baseImageUrl
  })
  .then(data => {
    console.log("image data:", data);
  })
  .catch(error => {
    console.error("toBase64Url error", err);
  });

//use ES7
async () => {
  const data = await magician.toBase64Url({
    cover: baseImageUrl
  });
  console.log("image data:", data);
};

outputType

async () => {
  // outputType = 'dataUrl'  default
  const data = await magician.toBase64Url({
    cover: baseImageUrl,
    outputType: "dataUrl"
  });
  console.log("image data:", data);

  // outputType = 'blob'
  const blob = await magician.toBase64Url({
    cover: baseImageUrl,
    outputType: "blob"
  });
  console.log("image blob:", URL.createObjectURL(blob));
};

Development

git clone https://github.com/lijinke666/photo-magician.git
npm install | yarn
npm start

API

/**
 * @name toBase64Url
 * @description get base64 data of the image
 * @param {Object} options
 * @param {String | Object} options.cover cover url | image element node   The next cover parameter is the same as this.
 * @return base64 data
 */
magician.toBase64Url({
  cover: baseImageUrl
});

/**
 * @name getPrimaryColor
 * @description get primary color of the image
 * @param {Object} options
 * @param {String | Object} options.cover
 * @return primaryColor
 */

magician.getPrimaryColor({
  cover: watermark
});

/**
 * @name compressImage()
 * @description compress of the image
 * @param {Object} options
 * @param {String | Object} options.cover
 * @param {Number}  options.quality range(0-1) default '0.92'
 * @return base64 data
 */
magician.compressImage({
  cover: baseImageUrl,
  quality: 0.12
});

/**
 * @name clipImage()
 * @description cut clip of the image
 * @param {object} Options
 * @param {String | Object} options.cover
 * @param {Number} options.scale Image zooming   default '1.0'
 * @param {Array} options.coordinate [[x1,y1],[x2,y2]]
 * @return base64 data
 */
magician.clipImage({
  cover: baseImageUrl,
  scale: 1.0,
  coordinate: [[200, 200], [[300, 300]]
});

/**
 * @name rotateImage()
 * @description Rotate the image
 * @param {String | Object} cover 图片地址或节点
 * @param {Number} rotate 旋转比例 (0 -360 ) °
 */
magician.rotateImage({
  cover: baseImageUrl,
  rotate: 20
});

/**
 * @name addWaterMark
 * @description Add text or picture watermark to the image.
 * @param {Object} options
 * @param {String | Object} options.cover
 * @param {String} options.waterMark waterMark
 * @param {String} options.mode "image | text"  Specify whether it is a image or a text. [default 'text']
 * @param {Boolean} options.fontBold If it's text, then bold [default 'true']
 * @param {Number} options.fontSize If it's text, what font size is it?  [default 20]
 * @param {String} options.fontColor if it's text, If it's text, what font color is it? [default'rgba(255,255,255,.5)']
 * @param {Number} options.width if it's image what width of the image [default '50']
 * @param {NUmber} options.height if it's image what height of the image [default '50']
 * @param {NUmber} options.opacity opacity of the image  [default '0.5']
 * @param {Array} options.coordinate [x,y] [default '[0,0]']
 */
magician.addWaterMark({
  cover: baseImageUrl,
  mode: "image",
  waterMark: watermark,
  width: 60,
  height: 60,
  opacity: 0.8,
  coordinate: [330, 300]
});

/**
 * @name addWaterMark
 * @param Same as above
 */
magician.addWaterMark({
  cover: baseImageUrl,
  mode: "text",
  waterMark: "photo-magician.js",
  fontBold: false,
  fontSize: 20,
  fontColor: "#396",
  coordinate: [10, 20]
});

/**
 * @name addImageFilter
 * @param {Object} options
 * @param {String | Object} options.cover
 * @param {String} options.mode  filter name  "vintage" | "blackWhite" | "relief" | "blur"
 */
magician.addImageFilter({
  cover: baseImageUrl,
  mode: "vintage"
});

License

MIT