Forum Moderators: coopster

Message Too Old, No Replies

PHP Imagepng and CUPS

Keep getting PNG output in the browser

         

HeadBut

7:27 pm on May 29, 2006 (gmt 0)

10+ Year Member



I'm guessing the reason I can't print is because the output is not making it to a file. Here is what I'm trying to do:

$PageWidth = 600;
$font = '/Library/Fonts/Chalkboard.ttf'; /* on a Mac */
$fontSize = 12;
$CheckText = "All the text I want to print.";

$tmpfname = tempnam("/tmp", ".png");
$FileHandle = fopen($tmpfname, "w");

$NumberofLines = Count(explode("
", $CheckText));

$PageLength = ($fontSize * $NumberofLines);
$PrintImage = imagecreate($PageWidth, $PageLength);
$black = imagecolorallocate($PrintImage, 0, 0, 0);

imagettftext($PrintImage, $fontSize, 0, 10, 5, $black, $font, $CheckText);

$FinalResulToPrint = imagepng($PrintImage);

fwrite($FileHandle, $FinalResulToPrint);

$FilePathOfFileReadyToPrint = realpath($tmpfname);

/* The Print Command */
if(!exec("lp -d TSP600__STR_T_U001_ $FilePathOfFileReadyToPrint", $PrintResult)){$PrintStatus = false;}

then I do the fclose and imagedestroy.

Thanks
Earbite

HeadBut

12:11 am on May 30, 2006 (gmt 0)

10+ Year Member



I can find tons of info/tutorials on dynamic image creation (to the browser).. I want to create a file... any pointers?

jatar_k

4:15 pm on May 30, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you can pass a filename to this function

$FinalResulToPrint = imagepng($PrintImage);

that will output it to that filename instead of the browser