Git Product home page Git Product logo

image-cropper's Introduction

Hi there!

鹅鹅鹅's GitHub stats

  • 🚢 Open source enthusiasts
  • 🔭 Technology stack: Vue, Mini Program
  • 💬 A programmer with ideas,Like to simplify complicated things
  • ❤️ Cats 😸, Mobile Games 🎮 and Music 🎵

image-cropper's People

Contributors

1977474741 avatar chen-yt avatar microj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

image-cropper's Issues

plus7 不兼容

对应工具或者iOS或者Andriod的版本号

微信版本号

代码截图

重现步骤

期待的行为

实际的行为

this.cropper.imgReset(); 图片位置

按照文档的使用,在bindimageload响应函数中调用this.cropper.imgReset()后,图片相对裁剪前和整个屏幕总是下降一小块。
image

控制整个组件的长宽

对应工具或者iOS或者Andriod的版本号 无

微信版本号 无

代码截图 无

重现步骤

期待的行为

实际的行为 想要改变整个区域的大小,应该怎样控制

IOS上裁剪缺失的问题

对应工具或者iOS或者Andriod的版本号
IOS 12.1.2

微信版本号
7.0.3

感谢作者提供这个相当有用的组件。
我发现在IOS上裁剪会有一定几率缺失(不是100%复现,但几率很高),见下图。
我把canvas#image-cropperi显示在左上角了,export_scale也设成1,这样方便对比。

img-1
img-2

可以看出来,此时canvas右边和下边是有白边,canvas style里的width和height已经改成新值:_canvas_width * export_scale = 300 * 1,但是canvas实际context的大小仍然是默认大小200x200(data里定义的_canvas_width)。

排查后发现,wxml里定义了canvas的宽高 width:{{_canvas_width * export_scale}},而_canvas_width的值是在attached里定义的,所以我怀疑在IOS上,attached里更改style里的width和height后,canvas context的宽高并未跟着改变,并且attached生命周期和wxml canvas的初始化顺序不是固定的,这可能也解释了bug为何不是必现的。

目前我的修复方案是把wxml里的canvas style改成 width:{{width * export_scale}}px;height:{{height * export_scale}}px,这样canvas在初始化时就等于裁剪框的宽高了,从而避免这个问题,但不知是否有其他影响

js文件中最后一句

_preventTouchMove(){ }
这个函数是专门放到外部的吗,还是错位了,应该提到里面一层,就不会报错了

文档建议

文档中几个位置似乎有些问题
1、
"usingComponents": {
"navigationBarTitleText": "裁剪图片",
"image-cropper": "../image-cropper/image-cropper",
"disableScroll": true,
}
正确应该为:
"navigationBarTitleText": "裁剪图片",
"disableScroll": true,
"usingComponents": {
"image-cropper": "../image-cropper/image-cropper"
}

2、
wxss文件末尾中的@import '../image-cropper/image-cropper.wxss'似乎没有必要。

Maximum call stack size exceeded;

对应工具或者iOS或者Andriod的版本号

微信版本号

代码截图

重现步骤
大量使用时有部分用户会产生错误:Maximum call stack size exceeded;
触发该错误的方法是”_cutTouchMove“
期待的行为

实际的行为

我原图是jpg,裁剪过后返回png,

对应工具或者iOS或者Andriod的版本号
小程序开发工具
期待的行为
如果我的照片是jpg,那么我裁剪过后的照片也是jpg。而不是返回png撒

建议提供是否固定裁剪框的参数

重现步骤

  1. 在组件挂载之后,使用this.imageCropper.setCutXY(left, top);修改裁剪框位置{cut_top,cut_left }
  2. 触碰界面(Image元素)触发touchend,在回调_end中,最终调用了setCutCenter方法,使原先的裁剪框位置设置失效变回居中效果

期待的行为
增加固定裁剪框参数 fixCropBox

目前解决办法
注释掉image-cropper.js中的_moveStop方法中的居中代码

//停止移动时需要做的操作
    _moveStop() {
      //清空之前的自动居中延迟函数并添加最新的
      clearTimeout(this.data.TIME_CUT_CENTER);
      /* todo 不要居中重置 */
      /* this.data.TIME_CUT_CENTER = setTimeout(() => {
        //动画启动
        if (!this.data._cut_animation) {
          this.setData({
            _cut_animation: true
          });
        }
        this.setCutCenter();
      }, 1000) */
      //清空之前的背景变化延迟函数并添加最新的
      clearTimeout(this.data.TIME_BG);
      this.data.TIME_BG = setTimeout(() => {
        if (this.data._flag_bright) {
          this.setData({
            _flag_bright: false
          });
        }
      }, 2000)
    }

提几个bug和一个建议

很感谢鹅神做出这样一款小程序裁剪组件,方便好用功能强大。我在使用的时候发现如果在setData里设置图片的宽高,也就是img_width与img_height会导致图片加载的时候出现位移的情况,触摸一下裁剪框就会回到中间,我发现watch方法里没有img_width(value, that)与img_height(value, that),不知是不是和这个有关。我尝试加了一下,不知有没有问题:

            img_width(value, that) {
                that.data.INIT_IMGWIDTH = value
                that.data.INIT_IMGHEIGHT = that.data.img_height
                that._computeCutSize()
            },
            img_height(value, that) {
                that.data.INIT_IMGWIDTH = that.data.img_width
                that.data.INIT_IMGHEIGHT = value
                that._computeCutSize()
            },

第二个bug是getImg(res)方法获取图片有时候图片会出现拉伸,导致裁剪过多,并不是必现,有时候又正常,不知是不是和我设置img_width与img_height有关。
一个建议:你在输出图片的时候通过

destWidth: this.data.width * this.data.export_scale,
destHeight: Math.round(this.data.height) * this.data.export_scale,

来放大图片,但是这样图片会失真,因为本身的canvas绘制的图片尺寸比较小,这样把小图拉大就会变模糊。于是我尝试在你的canvas下面加一个大尺寸的canvas,跟随你的canvas绘制,在 _draw(callback)方法里最后面加上:

if (callback) {
 let img_width2 = this.data.img_width * this.data.scale * this.data.export_scale
 let img_height2 = this.data.img_height * this.data.scale * this.data.export_scale
 var xpos2 = (this.data._img_left - this.data.cut_left) * this.data.export_scale
 var ypos2 = (this.data._img_top - this.data.cut_top) * this.data.export_scale
 this.data.ctxBig.translate(xpos2, ypos2)
 this.data.ctxBig.rotate((this.data.angle * Math.PI) / 180)
 this.data.ctxBig.drawImage(
  this.data.imgSrc,
  -img_width2 / 2,
  -img_height2 / 2,
  img_width2,
  img_height2
  )
  this.data.ctxBig.draw(false, () => {
    callback()
   })
  }

然后在getImg(getCallback)里wx.canvasToTempFilePath这个大的canvas即可:

wx.canvasToTempFilePath(
 canvasId: 'image-cropper-big',
 fileType: 'png',
 quality: this.data.quality,
 success: res => {
  let src = res.tempFilePath
  wx.getImageInfo({
   src: src,
   success: res => {
   let iw = res.width
   let ih = res.height
   getCallback({
   url: src,
   width: ih,
   height: iw
   })
  }
  })
  }
)

图片与裁剪框的位置

进入裁剪页面后裁剪框和图片不居中 过一会才会自动居中 但是图片还是会有一部分在裁剪框外面 就是 裁剪框上面会有一部分空白 只有手动移动后 才可以

getImg怎么调用?

对应工具或者iOS或者Andriod的版本号

微信版本号

代码截图

重现步骤

期待的行为

实际的行为

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.