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

taro-caman

v1.0.6

Published

Javascript (Ca)nvas (Man)ipulation for Wechat mini programs based on CamanJS

Downloads

12

Readme

taro-caman

Build Status

基于 CamanJS 的微信小程序 Canvas 像素级滤镜处理库

介绍

由于微信小程序中的 canvas 组件与 DOM Canvas 元素有较大差异,因此传统的 Canvas 处理库几乎无法在小程序中使用。taro-caman 由 CamanJS 封装而来并针对微信小程序进行了适配。其使用基本与 CamanJS 保持一致,能够对小程序中的 canvas 进行像素级别的图像滤镜处理。

安装

npm

mpvue 等支持 npm 的小程序开发框架中,可以直接使用 npm 进行安装:

npm install taro-caman

然后在项目中引入:

// es6 modules
import WxCaman from 'taro-caman'

// or cjs
var WxCaman = require('taro-caman').default

直接引入文件

将当前 repo 中 dist/ 目录下的 taro-caman.min.js 文件直接拷贝至你的小程序项目中的 vendor 目录下,然后在项目中引入:

var WxCaman = require('vendor/taro-caman.min.js').default

快速开始

小程序对于 canvas 组件限制较多,详情参考官方文档。在使用 taro-caman 前,我们必须在 WXML 中定义 canvas 组件并且设置 canvas-id。

<canvas style="width: 300px; height: 200px;" canvas-id="firstCanvas"></canvas>
Page({
  onReady: function (e) {
    // 使用 wx.createContext 获取绘图上下文 context
    var context = wx.createCanvasContext('firstCanvas')

    context.setStrokeStyle('#00ff00')
    context.setLineWidth(5)
    context.rect(0, 0, 200, 200)
    context.stroke()
    context.setStrokeStyle('#ff0000')
    context.setLineWidth(2)
    context.moveTo(160, 100)
    context.arc(100, 100, 60, 0, 2 * Math.PI, true)
    context.draw(false, function() {
      new WxCaman('firstCanvas', 300, 200, function () {
        this.brightness(10)
        this.contrast(30)
        this.sepia(60)
        this.saturation(-30)
        this.render()
      })
    })
  }
})

进阶使用

此处文档可直接参考 CamanJS 文档:AsvancedUsage

注:taro-caman 不支持 Cropping/Resizing 和 Events。

内置函数

此处文档可直接参考 CamanJS 文档:Built-In Functionality

支持基础滤镜如下:

  • Brightness
  • Channels
  • Clip
  • Colorize
  • Contrast
  • Curves
  • Exposure
  • Fill Color
  • Gamma
  • Greyscale
  • Hue
  • Invert
  • Noise
  • Saturation
  • Sepia
  • Vibrance

预设滤镜

taro-caman 支持以下预设滤镜:

  • vintage
  • lomo
  • sinCity
  • sunrise
  • crossProcess
  • orangePeel
  • love
  • grungy
  • pinhole
  • oldBoot
  • glowingSun
  • hazyDays
  • herMajesty
  • nostalgia
  • hemingway

其中,vintage/lomo/sunrise/grungy/pinhole/oldBoot/glowingSun/hazyDays/nostalgia 可接收一个 Boolean 参数,表示是否使用晕映效果,默认为 true,即使用晕映效果。

使用示例:

new WxCaman('firstCanvas', 300, 200, function () {
  this.lomo(false)
  this.render()
})

注意事项

  • 为了确保 taro-caman 准确获取 canvas 组件的像素数据,请务必在 draw 的回调函数中使用 taro-caman
  • taro-caman 需要获取到 canvas 组件的真实宽高。但在实际使用中 canvas 组件可能使用了 width: 90% 等相对宽高数值,此时可使用 wx.createSelectorQuery() 来获取到 canvas 组件渲染后的实际宽高,然后再进行 taro-caman 的初始化