You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
1.6 KiB
1 line
1.6 KiB
10 months ago
|
"use strict";function getCanvas(e,a){var o=e.canvasId,t=e.node,i=void 0===t||t,n=e.size,r=void 0===n||n;return new Promise(function(t,n){wx.createSelectorQuery().in(a).select("#".concat(o)).fields({node:i,size:r}).exec(function(e){e[0]?t(e[0].node):n({errMsg:"Canvas is not supported in the current environment."})})})}function createImage(e,i){var r=e.imageWidth,s=e.imageHeight,c=e.imageUrl;return new Promise(function(e,t){if("function"==typeof i.createImage){var n=wx.getSystemInfoSync().pixelRatio,a=i.getContext("2d"),o=i.createImage();o.onload=function(){a.drawImage(o,-r*n/2,-s*n/2,r*n,s*n),e(c)},o.onerror=function(){t({errMsg:"Image creation failed in canvas.createImage."})},o.src=c}else t({errMsg:"Canvas.createImage is not a function."})})}function toDataURL(e,n){var a=e.width,o=e.height,t=e.type,i=void 0===t?"image/png":t,r=e.quality,s=void 0===r?1:r;return new Promise(function(t){if("function"==typeof n.toDataURL)t(n.toDataURL(i,s));else if("function"==typeof wx.canvasToTempFilePath){var e=wx.getSystemInfoSync().pixelRatio;wx.canvasToTempFilePath({destWidth:a*e,destHeight:o*e,canvas:n,fileType:-1!==i.indexOf("png")?"png":"jpg",quality:s,success:function(e){return t(e.tempFilePath)},fail:function(){return t("")}})}else t("")})}function downloadImage(e){return new Promise(function(t,n){/^http/.test(e)&&!/^http:\/\/tmp/.test(e)?wx.downloadFile({url:e,success:function(e){200===e.statusCode?t(e.tempFilePath):n({errMsg:e.errMsg})},fail:function(e){n(e)}}):t(e)})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.getCanvas=getCanvas,exports.createImage=createImage,exports.toDataURL=toDataURL,exports.downloadImage=downloadImage;
|