[rrd-users] alpha channel on rrdtool PNG vs. TCPDF (Solved)
Valter Douglas Lisbôa Jr.
douglas at trenix.com.br
Sun Jun 29 18:21:15 CEST 2008
I solved it! So, I'm posting the solution for others with a similar problem
(Some versions of IE appear can't be capable to handle a PNG with
transparency).
It's a snip of my PHP OO code.
---------------------- snip ----------------------
// Creates a PDF with the graphs requireds.
public function getPDF() {
try {
$pdf = new TCPDF();
$pdf->Open();
... // A lot of boring PDF preparation code
// Temporary file
$png = tempnam("../tmp/", "graph");
// Calls the rrdtool command to generate the PNG
$this->getCPU($png, ... other parameters ...); //
// Load, Remove all alpha and save in a new file
$img = ImageCreateFromPNG($png);
imageAlphaBlending($img, false);
imageSaveAlpha($img, false);
imagePNG($img, "$png.png");
// Load to PDF
$pdf->Image("$png.png", 30, 50);
// Remove all temporaries
unlink($png);
unlink("$png.png");
// Put PDF on screen
$pdf->Output();
} catch(Exception $err) {
throw new Exception('Graph Exception: ' . $err->getMessage());
}
}
---------------------- snip ----------------------
The tip is using imageAlphaBlending + imageSaveAlpha. The file size drops from
32KB to 21KB (better for me, I botter for PDF size ;-) ) and loads normally
on TCPDF.
Three hours of research before a I send the first post, more some minutes
to "google" the solution after that! Never Give up! :-D
If someone has another solution, it will be welcome.
On Sunday 29 June 2008 12:39:09 Valter Douglas Lisbôa Jr. wrote:
> Hello All!
>
> I'm new on this list, and this is my first post.
>
> Creating a System to load the graph generated in PNG format from rrdtool
> with PHP 5, I was very sucefull. However, when I try to put it on a PDF
> utilizing TCPDF 3.1.001 PHP class, I got a error.
>
> TCPDF error: Alpha channel not supported: file.png
>
> This class has a limitation from loading PNG with transparent colors, it's
> a known bug not corrected yet, and this is the only format in common with
> rrdtool. So, I try to remove the PNG's alpha channel by rrdtool, definning
> every color with -c or in LINE/AREA/etc with the solid attribute (FF) on
> the end of color. It wasn't exactly a success :-( the error continues.
>
> Then I "googling" for PHP functions to find a way to remove the alpha
> channel, I already try to detect if exists a color with
> imagecolortransparent(), with another failure (it returns -1).
>
> Going to the point! How can I generate with rrdtool 1.2.x a PNG without a
> alpha channel? Or does anyone can point me the way to do this with another
> software on-the-fly?
>
> Thanks in advance
--
Valter Douglas Lisbôa Jr.
Sócio-Diretor
Trenix - IT Solutions
"Nossas Idéias, suas Soluções!"
www.trenix.com.br
contato at trenix.com.br
Tel. +55 19 3402.2957
Cel. +55 19 9183.4244
More information about the rrd-users
mailing list