4

在 FPDF 的官方文档中,它说 PNG 不支持 alpha 通道。

有什么解决方法吗?

4

3 回答 3

6

如果您需要将透明图像放在另一个图像之上:使用 PHP 内置函数将一个图像复制到另一个图像上。然后你会得到一张包含两张图片的新图片。另存为非 alpha png,然后插入。

这里有一个组合图像所需的代码示例。

如果您希望文字在您的图片下方可见:首先插入图片,然后将您的文字写入文档。

于 2011-03-14T14:19:36.903 回答
5

Try this extension for FPDF:

http://valentin.dasdeck.com/php/fpdf/fpdf_alpha/

Short description from the page:

This script allows to use images (PNGs or JPGs) with alpha-channels. The alpha-channel can be either supplied as separate 8-bit PNG ("mask"), or, for PNGs, also an internal alpha-channel can be used. For the latter, the GD 2.x extension is required.

Specifying a separate mask image has several advantages: - no GD required. - Better quality (full 8-bit alpha channel, whereas GD internally only supports 7-bit alpha channels) - much faster (extraction of embedded alpha-channel has to be done pixel-wise)

function Image(string file, float x, float y [, float w [, float h [, string type [, mixed link [, boolean isMask [, int maskImg]]]]]])

Same parameters as for original Image()-method, with 2 additional (optional) parameters: isMask: if specified and true, the image is used as mask for other images. In this case, the parameters x, y, w and h will be ignored and the mask image itself is not visible on the page. maskImg: number of image resource (as returned by previously called Image() with isMask parameter set to true) that will be used as mask for this image.

function ImagePngWithAlpha(string file, float x, float y [, float w [, float h [, mixed link]]])

Same parameters as for original Image()-method, but without a type parameter.

于 2011-04-13T19:10:28.117 回答
1

这对我有用,谢谢大家。我基本上包括了上面的扩展(http://valentin.dasdeck.com/php/fpdf/fpdf_alpha/),然后扩展类如下:

在 fpdf_tpl.php 中需要('PDF_ImageAlpha.php');

class FPDF_TPL extends PDF_ImageAlpha

在 PDF_ImageAlpha.php 中:

class PDF_ImageAlpha extends FPDF{
Inside of here I chaged the image() function to F_image() to avoid clashing (probably       should have used namespaces). With a quick search and replace you will see that this needs replacing 2 more times.
}

然后在我的 workhorse.php 文件中,我调用了函数 F_image() 而不是 image(),这解决了我的问题。

谢谢!!!

于 2013-11-19T13:56:29.937 回答