fix:用canvas裁剪缩放1080×1080替代plus.zip(不兼容nvue)
This commit is contained in:
parent
0a572aae0f
commit
a83e43af39
@ -66,6 +66,9 @@
|
|||||||
</view>
|
</view>
|
||||||
<image class="cc-preview-img" :src="previewSrc" mode="aspectFill" :style="'width:' + previewSize + 'px;height:' + previewSize + 'px;'"></image>
|
<image class="cc-preview-img" :src="previewSrc" mode="aspectFill" :style="'width:' + previewSize + 'px;height:' + previewSize + 'px;'"></image>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<!-- 隐藏的canvas(用于裁剪缩放) -->
|
||||||
|
<canvas canvas-id="resizeCanvas" style="width:1080px;height:1080px;position:fixed;left:-9999px;top:-9999px;"></canvas>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -141,27 +144,28 @@
|
|||||||
var w = info.width
|
var w = info.width
|
||||||
var h = info.height
|
var h = info.height
|
||||||
var size = Math.min(w, h)
|
var size = Math.min(w, h)
|
||||||
var clipX = Math.floor((w - size) / 2)
|
var sx = Math.floor((w - size) / 2)
|
||||||
var clipY = Math.floor((h - size) / 2)
|
var sy = Math.floor((h - size) / 2)
|
||||||
plus.zip.compressImage({
|
// 用canvas裁剪 + 缩放
|
||||||
src: srcPath,
|
var ctx = uni.createCanvasContext('resizeCanvas', that)
|
||||||
dst: '_doc/sq_' + Date.now() + '.jpg',
|
ctx.drawImage(srcPath, sx, sy, size, size, 0, 0, 1080, 1080)
|
||||||
width: '1080',
|
ctx.draw(false, function() {
|
||||||
height: '1080',
|
setTimeout(function() {
|
||||||
quality: 95,
|
uni.canvasToTempFilePath({
|
||||||
overwrite: true,
|
canvasId: 'resizeCanvas',
|
||||||
clip: {
|
x: 0, y: 0,
|
||||||
x: clipX,
|
width: 1080, height: 1080,
|
||||||
y: clipY,
|
destWidth: 1080, destHeight: 1080,
|
||||||
width: size,
|
fileType: 'jpg',
|
||||||
height: size
|
quality: 1,
|
||||||
}
|
success: function(res) {
|
||||||
},
|
that.capturedList.push(res.tempFilePath)
|
||||||
function(res) {
|
},
|
||||||
that.capturedList.push(res.target)
|
fail: function() {
|
||||||
},
|
that.capturedList.push(srcPath)
|
||||||
function() {
|
}
|
||||||
that.capturedList.push(srcPath)
|
}, that)
|
||||||
|
}, 300)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
fail: function() {
|
fail: function() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user