将 PHP 条形码流式传输到 IMG 标签
Streaming a PHP Barcode to and IMG tag
我有一个独特的问题,由于平台限制,我只能使用 HTML 来发送收据电子邮件。
收据上需要生成 CODE128 条码。不幸的是,因为我只能在电子邮件模板中使用 HTML,所以我想弄清楚如何创建这些条形码并 link 它们带有 IMG 标签。
所以我目前的想法是在不同的服务器上使用 PDFCrowd php 库,然后在电子邮件模板中创建一个 IMG 标签,SRC 是对另一台服务器的 GET 请求 URL上面有 php 库。
然后我将使用内联 css 生成 html 并将其转换为图像并将其流回。
HTML 电子邮件模板 IMG 标签是否适用于那种类型的 URL 设置!?
...这是一个快速而肮脏的 shopify 解决方案。
<?php
require 'pdfcrowd.php';
try
{
// create the API client instance
$client = new \Pdfcrowd\HtmlToImageClient("username", "apikey");
// configure the conversion
$client->setOutputFormat("png");
// create output file for conversion result
$output_file = fopen("HelloWorld.png", "wb");
// run the conversion and store the result into an image variable
$image = $client->convertString("<html><body><h1>Hello World!</h1></body></html>");
// write the image the into the output file
fwrite($output_file, $image);
// close the output file
fclose($output_file);
}
catch(\Pdfcrowd\Error $why)
{
// report the error to the standard error stream
fwrite(STDERR, "Pdfcrowd Error: {$why}\n");
}
?>
您可以使用 github here 上的条形码生成器。我记得以前有过类似的需求,下载了条形码生成器并完成了工作。
例1:
参数:
- 文本:“0”(默认)
- 尺寸:“20”(默认)
- 代码类型:“Code128”(默认)
- 方向:“水平”(默认)
HTML源代码:
<img alt="testing" src="/code/barcode.php" />
结果:
例二:
参数:
- 文本:“测试”
- 尺寸:“20”(默认)
- 代码类型:“Code128”(默认)
- 方向:“水平”(默认)
- 打印:“真”
HTML源代码:
<img alt="testing" src="/code/barcode.php?text=testing&print=true" />
结果:
示例 3:
参数:
- 文本:“测试”
- 尺码:“40”
- 代码类型:“Code39”
- 方向:“水平”(默认)
- 打印:“真”
HTML源代码:
<img alt="TESTING" src="/code/barcode.php?codetype=Code39&size=40&text=TESTING&print=true" />
结果:
来源中有更多示例 link。
我有一个独特的问题,由于平台限制,我只能使用 HTML 来发送收据电子邮件。
收据上需要生成 CODE128 条码。不幸的是,因为我只能在电子邮件模板中使用 HTML,所以我想弄清楚如何创建这些条形码并 link 它们带有 IMG 标签。
所以我目前的想法是在不同的服务器上使用 PDFCrowd php 库,然后在电子邮件模板中创建一个 IMG 标签,SRC 是对另一台服务器的 GET 请求 URL上面有 php 库。
然后我将使用内联 css 生成 html 并将其转换为图像并将其流回。
HTML 电子邮件模板 IMG 标签是否适用于那种类型的 URL 设置!?
...这是一个快速而肮脏的 shopify 解决方案。
<?php
require 'pdfcrowd.php';
try
{
// create the API client instance
$client = new \Pdfcrowd\HtmlToImageClient("username", "apikey");
// configure the conversion
$client->setOutputFormat("png");
// create output file for conversion result
$output_file = fopen("HelloWorld.png", "wb");
// run the conversion and store the result into an image variable
$image = $client->convertString("<html><body><h1>Hello World!</h1></body></html>");
// write the image the into the output file
fwrite($output_file, $image);
// close the output file
fclose($output_file);
}
catch(\Pdfcrowd\Error $why)
{
// report the error to the standard error stream
fwrite(STDERR, "Pdfcrowd Error: {$why}\n");
}
?>
您可以使用 github here 上的条形码生成器。我记得以前有过类似的需求,下载了条形码生成器并完成了工作。
例1:
参数:
- 文本:“0”(默认)
- 尺寸:“20”(默认)
- 代码类型:“Code128”(默认)
- 方向:“水平”(默认)
HTML源代码:
<img alt="testing" src="/code/barcode.php" />
结果:
例二:
参数:
- 文本:“测试”
- 尺寸:“20”(默认)
- 代码类型:“Code128”(默认)
- 方向:“水平”(默认)
- 打印:“真”
HTML源代码:
<img alt="testing" src="/code/barcode.php?text=testing&print=true" />
结果:
示例 3:
参数:
- 文本:“测试”
- 尺码:“40”
- 代码类型:“Code39”
- 方向:“水平”(默认)
- 打印:“真”
HTML源代码:
<img alt="TESTING" src="/code/barcode.php?codetype=Code39&size=40&text=TESTING&print=true" />
结果:
来源中有更多示例 link。