Я генерирую изображение штрих-кода с использованием некоторых библиотек JS, штрих-код генерируется нормально, однако мне нужно отправить этот штрих-код в динамическом электронном письме.скрипт генерации штрих-кода:
<meta http-equiv="content-type" content="image/jpeg; charset=UTF-8">
<!--
Copyright (c) 2011-2018 Mark Warren.
See the LICENSE file in the bwip-js root directory
for the extended copyright notice.
-->
<script type="text/javascript" src="bwipp.js"></script>
<script type="text/javascript" src="bwipjs.js"></script>
<script type="text/javascript" src="lib/jquery.js"></script>
<script type="text/javascript" src="lib/jquery-ui.min.js"></script>
<script type="text/javascript" src="lib/xhr-fonts.js"></script>
<script type="text/javascript" src="lib/bitmap.js"></script>
<script type="text/javascript" src="lib/symdesc.js"></script>
<script type="text/javascript" src="lib/canvas-toblob.js"></script>
<script type="text/javascript" src="lib/filesaver.js"></script>
<script type="text/javascript">
$(document).ready(function() {
render();
});
function GetURLParameter(sParam)
{
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
return sParameterName[1];
}
}
}
function render() {
var elt = symdesc["gs1qrcode"];
var tech = GetURLParameter('text');
var text = tech.replace(/^\s+/,'').replace(/\s+$/,'');
var altx = '';
var opts = '';
var rot = '';
// Anti-aliased or monochrome fonts and scaling factors.
var monochrome = 1;
var scaleX = 2;
var scaleY = 2;
localStorage.setItem('bwipjsLastSymbol', elt.sym);
localStorage.setItem('bwipjsLastBarText', text);
localStorage.setItem('bwipjsLastAltText', altx);
localStorage.setItem('bwipjsLastOptions', opts);
localStorage.setItem('bwipjsLastScaleX', scaleX);
localStorage.setItem('bwipjsLastScaleY', scaleY);
localStorage.setItem('bwipjsLastFontMono', monochrome ? 1 : 0);
localStorage.setItem('bwipjsLastRotation', rot);
var bw = new BWIPJS(bwipjs_fonts, monochrome);
// Clear the page
$('#output').text('');
$('#stats').text('');
$('#proof-img').css('visibility', 'visible');
$('.saveas').css('visibility', 'visible');
var canvas = document.getElementById('canvas');
canvas.height = 1;
canvas.width = 1;
canvas.style.visibility = 'visible';
// Convert the options to a dictionary object, so we can pass alttext with
// spaces.
var tmp = opts.split(' ');
opts = {};
for (var i = 0; i < tmp.length; i++) {
if (!tmp[i]) {
continue;
}
var eq = tmp[i].indexOf('=');
if (eq == -1) {
opts[tmp[i]] = true;
} else {
opts[tmp[i].substr(0, eq)] = tmp[i].substr(eq+1);
}
}
// Add the alternate text
if (altx) {
opts.alttext = altx;
opts.includetext = true;
}
// We use mm rather than inches for height - except pharmacode2 height
// which is expected to be in mm
if (+opts.height && elt.sym != 'pharmacode2') {
opts.height = opts.height / 25.4 || 0.5;
}
// Likewise, width.
if (+opts.width) {
opts.width = opts.width / 25.4 || 0;
}
// BWIPP does not extend the background color into the
// human readable text. Fix that in the bitmap interface.
if (opts.backgroundcolor) {
bw.bitmap(new Bitmap(canvas, rot, opts.backgroundcolor));
delete opts.backgroundcolor;
} else {
bw.bitmap(new Bitmap(canvas, rot));
}
// Set the scaling factors
bw.scale(scaleX, scaleY);
// Add optional padding to the image
bw.bitmap().pad(+opts.paddingwidth*scaleX || 0,
+opts.paddingheight*scaleY || 0);
var ts0 = Date.now();
try {
// Call into the BWIPP cross-compiled code.
BWIPP()(bw, elt.sym, text, opts);
// Allow the font manager to demand-load any required fonts
// before calling render().
var ts1 = Date.now();
bwipjs_fonts.loadfonts(function(e) {
if (e) {
} else {
show();
}
});
} catch (e) {
// Watch for BWIPP generated raiseerror's.
return;
}
// Draw the barcode to the canvas
function show() {
bw.render();
var ts2 = Date.now();
canvas.style.visibility = 'visible';
}
}
</script>
<canvas id="canvas" width=1 height=1 style="border:1px solid #fff;visibility:hidden"></canvas>
</body>
</html>
Я использую тег изображения в скрипте генерации электронной почты для получения штрих-кода:
*<IMG
src="http://localhost:88/test/bwip-js-master/demo.php?bcid=gs1qrcode&text=(91)002(92)1(93)16250331840(94)HM(95)SE(253)000000000000000000000&includetext&custinfoenc=character&scale=2">*
Однако изображение не отображается в электронном письме.Может ли кто-нибудь подсказать, как я могу отобразить штрих-код в теге изображения, используя приведенный выше код, чтобы он появился в электронном письме.Любые предложения будут с благодарностью.
Спасибо, Ашиш