feat:拍照后plus.zip.compressImage裁剪为1080×1080
This commit is contained in:
parent
4d37e5d57b
commit
3856d28629
@ -76,6 +76,7 @@
|
||||
</view>
|
||||
<image class="cc-preview-img" :src="previewSrc" mode="aspectFill" :style="'width:' + previewSize + 'px;height:' + previewSize + 'px;'"></image>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@ -137,9 +138,49 @@
|
||||
path = e.detail.path || ''
|
||||
}
|
||||
if (path) {
|
||||
this.capturedList.push(path)
|
||||
this.resizeToSquare(path)
|
||||
}
|
||||
},
|
||||
// 裁剪为 1080×1080 正方形
|
||||
resizeToSquare(srcPath) {
|
||||
var that = this
|
||||
uni.getImageInfo({
|
||||
src: srcPath,
|
||||
success: function(info) {
|
||||
var w = info.width
|
||||
var h = info.height
|
||||
// 居中裁剪正方形
|
||||
var size = Math.min(w, h)
|
||||
var clipX = Math.floor((w - size) / 2)
|
||||
var clipY = Math.floor((h - size) / 2)
|
||||
// 使用 5+ 原生压缩 API 裁剪 + 缩放到 1080x1080
|
||||
plus.zip.compressImage({
|
||||
src: srcPath,
|
||||
dst: '_doc/resize_' + Date.now() + '.jpg',
|
||||
width: '1080',
|
||||
height: '1080',
|
||||
quality: 90,
|
||||
overwrite: true,
|
||||
clip: {
|
||||
x: clipX,
|
||||
y: clipY,
|
||||
width: size,
|
||||
height: size
|
||||
}
|
||||
},
|
||||
function(res) {
|
||||
that.capturedList.push(res.target)
|
||||
},
|
||||
function() {
|
||||
// 失败时用原始路径
|
||||
that.capturedList.push(srcPath)
|
||||
})
|
||||
},
|
||||
fail: function() {
|
||||
that.capturedList.push(srcPath)
|
||||
}
|
||||
})
|
||||
},
|
||||
flipCamera() {
|
||||
this.facing = this.facing === 'back' ? 'front' : 'back'
|
||||
this.$refs.cameraRef.changeFacing(this.facing)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user