jslib-tools
Version:
js工具库 封装常用的工具函数 如深拷贝 时间转换日期格式化、浏览器判断等,提高开发效率
78 lines (59 loc) • 3.22 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: canvas/getImgBase64.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: canvas/getImgBase64.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* 获取图片的base64 url
* @param {string} url 图片url
* @returns {Promise} 图片base64信息
*/
export function getImgBase64(url) {
/* eslint-disable */
var Img = new Image(),
dataURL = "";
Img.setAttribute("crossOrigin", "anonymous");
Img.src = url;
return new Promise((resolve, reject) => {
Img.onload = function() {
var canvas = document.createElement("canvas"),
width = Img.width,
height = Img.height;
var ctx = canvas.getContext("2d");
var scale = 5;
ctx.scale(scale, scale);
canvas.width = width * scale;
canvas.height = height * scale;
ctx.drawImage(Img, 0, 0, width * scale, height * scale);
dataURL = canvas.toDataURL("image/png");
resolve(dataURL);
};
});
}</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#callHandler">callHandler</a></li><li><a href="global.html#dateFormat1">dateFormat1</a></li><li><a href="global.html#dateFormat2">dateFormat2</a></li><li><a href="global.html#debounce">debounce</a></li><li><a href="global.html#elDateFormat">elDateFormat</a></li><li><a href="global.html#exportXls">exportXls</a></li><li><a href="global.html#getBrowserModel">getBrowserModel</a></li><li><a href="global.html#getDefaultAvatar">getDefaultAvatar</a></li><li><a href="global.html#getDeviceModel">getDeviceModel</a></li><li><a href="global.html#getImgBase64">getImgBase64</a></li><li><a href="global.html#getThumbnails">getThumbnails</a></li><li><a href="global.html#handleEmoji">handleEmoji</a></li><li><a href="global.html#handleParam">handleParam</a></li><li><a href="global.html#handleText">handleText</a></li><li><a href="global.html#isArray">isArray</a></li><li><a href="global.html#isEmoji">isEmoji</a></li><li><a href="global.html#isIDCard">isIDCard</a></li><li><a href="global.html#isMobile">isMobile</a></li><li><a href="global.html#isObject">isObject</a></li><li><a href="global.html#isSpecialChar">isSpecialChar</a></li><li><a href="global.html#parseTime">parseTime</a></li><li><a href="global.html#setVideoPlay">setVideoPlay</a></li><li><a href="global.html#throttle">throttle</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Thu Jun 17 2021 13:34:59 GMT+0800 (GMT+08:00)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>