PHP Doku:: Zeichnet ein BMP - function.printer-draw-bmp.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzWindowsbasierte ErweiterungenPrinterPrinter Funktionenprinter_draw_bmp

Ein Service von Reinhard Neidl - Webprogrammierung.

Printer Funktionen

<<printer_delete_pen

printer_draw_chord>>

printer_draw_bmp

(PECL printer SVN)

printer_draw_bmpZeichnet ein BMP

Beschreibung

void printer_draw_bmp ( resource $handle , string $filename , int $x , int $y [, int $width ], int $height )

Diese Funktion zeichnet einfach das BMP filename an die Position x, y. handle muss ein gültiger Druckerhandler sein.

Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.

Beispiel #1 printer_draw_bmp() Beispiel

<?php
$handle 
printer_open();
printer_start_doc($handle"Mein Dokument");
printer_start_page($handle);

printer_draw_bmp($handle"c:\\graphik.bmp"11);

printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
?>

5 BenutzerBeiträge:
- Beiträge aktualisieren...
codeslinger at compsalot dot com
21.02.2007 20:47
Don't get confused by the example.  The X Y offset is Base 0  not 1.  The example was trying to show that you could position the image elsewhere.

Also, the X Y offsets accept a negative value which can be very handy if you want to print just part of the image.  Such as when splitting an image across multiple pages.

Most (all?) printers will shift your output by the amount of the "unprintable" area.

Suppose you want to print an image at exactly X = 0.25, Y = 0.25 inches (from the top left).

On a typical printer with an unprintable area of 0.116 inches, the printer adds that amount as an offset.  So, to compensate you just subtract the offset. 

$X = 0.25 - 0.116;
$Y = 0.25 - 0.116;

With the result being that your image will be physically located where you intended.

Keep in mind that the unprintable area can be a different amount for the X and Y, for this example printer they both just happen to be the same.

Now the catch is that printer_get_option does not provide a way to get the unprintable area size.
Fuzzmaster
1.02.2006 0:30
Added a bit a fuzz:

  function print_img($doc,$img,$res,$pos_x,$pos_y)
    {
     $img_size = getimagesize($img);
     $img_resolution = $res;

     $img_width = $img_size[0];
     $img_height = $img_size[1];

     echo $img_width.'<BR>';
     echo $img_height.'<BR>';

     $ptr_resolution_x = printer_get_option($doc, PRINTER_RESOLUTION_X);
     $ptr_resolution_y = printer_get_option($doc, PRINTER_RESOLUTION_Y);

     echo $ptr_resolution_x.'<BR>';
     echo $ptr_resolution_y.'<BR>';

     $img_scale_x = $ptr_resolution_x / $img_resolution;
     $img_scale_y = $ptr_resolution_y / $img_resolution;

     echo $img_scale_x.'<BR>';
     echo $img_scale_y.'<BR>';

     $ptr_width = $img_width * $img_scale_x;                           
     $ptr_height = $img_height * $img_scale_y;

     echo $doc.'<BR>';
     echo $ptr_width.'<BR>';
     echo $ptr_height.'<BR>';
 
     printer_draw_bmp($doc,$img,$pos_x,$pos_y,$ptr_width,$ptr_height);
    }

print_img($handle, '../img/someimage.bmp', 72, 10, 10);

Of course, if someone can figure out how to capture the resolution of the image from the file that's one less value to manually assign.
ramiro_puc[AT]hotmail[DOT]com
15.01.2006 11:51
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);
?>
da_vinci7[at]hotmail[dot]com
17.03.2005 11:25
what i notice was that
[qoute]
void printer_draw_bmp ( resource handle, string filename, int x, int y)
[/qoute]
is only that here only the starting x and y are shown
and that if you have an bmp with the size 600 x 120 wil be shown as 600x120 pixels and printed very very smale

and when i tried giving ending x and y like this:
<?
  printer_draw_bmp
($handle, $file, 1, 1, 4600, 860)
?>

it printed the image in the correct size
lapoA at TseanetD dot O dot Tcom
8.12.2004 19:08
something I found out the hard way...
in order for the example above to work, the file being printed must be in a directory that has been opened for reading.
The example in the docs should probably have been listed as:
(There should probably be a check for the filename, but this should give an idea)

<?php
$dir
= 'c:\\somedir';
$file = 'myimage.bmp';

if (
is_dir($dir)) {
   if(
$dhandle = opendir($dir)) {
     
$handle = printer_open();
     
printer_start_doc($handle, "My Document");
     
printer_start_page($handle);

     
printer_draw_bmp($handle, $file, 1, 1);

     
printer_end_page($handle);
     
printer_end_doc($handle);
     
printer_close($handle);
   }
  
closedir($dhandle);
}
?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)