note 60728 deleted from function.printer-draw-bmp by sobak
| From: | sobak@php.net | Date: | Thu, 24 Nov 2016 20:30:33 +0000 |
| Subject: | note 60728 deleted from function.printer-draw-bmp by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207572@lists.php.net to get a copy of this message | ||
Note Submitter: ramiro_puc[AT]hotmail[DOT]com
----
When trying to print any image file it was getting a very, very small as someone said above. To
solve this problem, ive made a script that will calculate the correct size of image before output it
to printer.
Most of InkJet printers use 300 dpi. You can change values if you have any other printer... In this
case, im using a HP DeskJet 930c.
To make this script better, you can use GD to discover image resolution automatically.
<?php
$handle = printer_open();
printer_start_doc($handle, "My Document");
printer_start_page($handle);
$largura = 415; //Image Width in Pixels
$altura = 284; //Image Height in Pixels
$fator_x = $largura / 72; //Image Resolution (72 ppi)
$fator_y = $largura / 300; //Printer Resolution (300 dpi)
$fator_z = $fator_x / $fator_y;
$largura_f = $largura * $fator_z;
$altura_f = $altura * $fator_z;
printer_set_option($handle, PRINTER_MODE, "RAW");
printer_draw_bmp($handle, "c:\image.bmp", 1, 1, $largura_f, $altura_f);
printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
?>