将PHP条码流式传输到IMG标签 [英] Streaming a PHP Barcode to and IMG tag

查看:261
本文介绍了将PHP条码流式传输到IMG标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个独特的问题,由于平台的限制,我只需要使用HTML来发送收据电子邮件.

I have a unique problem where I have to use only HTML because of platform constraints to send out receipt emails.

收据上必须有一个CODE128条形码.不幸的是,因为我只能在电子邮件模板中使用HTML,所以我想弄清楚如何创建这些条形码并将其与IMG标签链接.

The receipts need to have a CODE128 Barcode generated on them. Unfortunately because I can only use HTML in the email template I am looking to figure out how to create these barcodes and link them with an IMG tag.

所以我目前的想法是在另一台服务器上使用PDFCrowd php库,然后在电子邮件模板中创建一个IMG标签,其中SRC是到另一台具有php库的服务器的GET请求URL.

So my current idea is to use the PDFCrowd php library on a different server and then create an IMG tag in the email template with the SRC being a GET Request URL to the other server with the php library on it.

然后,我将使用内联css生成html,并将其转换为图像并将其流回.

Then I would generate html with inline css and convert that to an image and stream it back out.

HTML电子邮件模板IMG标签可以与该类型的URL设置一起使用吗??

Would the HTML Email Template IMG tag work with that type of URL Setup!?

...这是一种快速而肮脏的shopify解决方案.

...This is for a quick and dirty shopify solution.

<?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");
}

?>

推荐答案

您可以使用在

You can use a barcode generator that can be found on github here. I remember being in a similar need sometime back, downloaded the barcode generator and it got the job done.

示例1:

参数:

  • 文本:"0"(默认)
  • 大小:"20"(默认值)
  • 代码类型:"Code128"(默认)
  • 方向:水平"(默认)

HTML源代码:

<img alt="testing" src="/code/barcode.php" />

结果:

示例2:

参数:

  • 文本:正在测试"
  • 大小:"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" />

结果:

源链接中的更多示例.

来源:David Scott Tufts

这篇关于将PHP条码流式传输到IMG标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆