/** * 文字列を画像データURIに変換 * * @param {String} str 文字列 * @param {boolean} strong 太字にするかどうか * @return {String} 画像データURI */ function stringToImage(str, strong) { const canvas = document.getElementById('value'); const context = canvas.getContext('2d'); context.clearRect(0, 0, canvas.width, canvas.height); context.font = (strong ? 'bold' : '') + ' 12pt MSゴシック'; context.textAlign = 'right'; context.textBaseline = 'bottom'; switch (str) { case 'Err': context.fillStyle = '#ff0000'; break; case 'NA': context.fillStyle = '#999999'; break; default: context.fillStyle = '#000000'; str += '℃'; } context.fillText(str, canvas.width, canvas.height); const uri = canvas.toDataURL(); return uri; }