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

hammerjs-image

v1.0.5

Published

hammerjs-image

Downloads

13

Readme

一个使用hammerjs进行图片缩放,旋转,拖放的工具


因为图片处理经常需要缩放旋转进行裁剪,所以做了这个东西,方便自己以后使用 简单来说,通过指定的div,通过宽度,高度计算出相对于图片原图的canvas大小然后图片处理返回canvas

在线演示demo

  • 0.webpack打包
  • 1.通用简单
  • 2.原图处理
  • 3.支持缩放,旋转,拖放,双击等常规操作
  • 4.返回canvas方便二次处理

调试测试

1.cnpm install 2.cnpm run dev

编译

1.cnpm run build

其他项目引用

1.cnpm install hammerjs-image -S

点击跳转参考示例

import HammerjsImage  from 'hammerjs-image'

var hi = new HammerjsImage({
    id: '#photo_area',
    //  el: document.getElementById('#photo_area'),
    img: '12.jpg',
    maxScale: 2,
    minScale: 0.5
})

使用方法,初始化

    <script type="text/javascript" src="hammer.min.js"></script>
    <script type="text/javascript" src="dist/hammerjs-image.js"></script>
    <div id="photo_area" style="width: 260px; height: 360px; background-color: black; overflow: hidden;">
    </div>
    
    var hi = new HammerjsImage({
        id: '#photo_area', //进行缩放的元素id,或使用el直接传入div元素,id权重较高
        //  el: document.getElementById('#photo_area'),
        img: '12.jpg', //需要进行缩放的图片,图片路径或Base64串
        maxScale: 2, //设置最大的缩放比例,默认2
        minScale: 0.5 //设定最小的缩放比例,默认0.5
    })
    

主动设置参数,如果不设置,将使用最后一次的值,设置后会影响对象的值

  hi.setTranslate3dInfo({
    rotation: rotation,
    scale: scale,
    offset_x: offset_x,
    offset_y: offset_y
  }).preview()
    

生成旋转,缩放,拖放后的canvas对象

  hi.translate3d()

生成旋转,缩放,拖放后的base64

  方法一~
  hi.translate3d().toDataURL()
  方法二~
  hi.getBase64()

切换图片

  方法一~
  hi.changeImg('12.jpg')
  方法二~
  hi.changeImg('base64')