| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
require_once(HTML2PS_DIR.'ps.image.encoder.stream.inc.php');
|
|
|
4 |
|
|
|
5 |
class PSL2ImageEncoderStream extends PSImageEncoderStream {
|
|
|
6 |
function by_lines($image, &$size_x, &$size_y) {
|
|
|
7 |
$lines = array();
|
|
|
8 |
|
|
|
9 |
$size_x = imagesx($image->get_handle());
|
|
|
10 |
$size_y = imagesy($image->get_handle());
|
|
|
11 |
|
|
|
12 |
$dest_img = imagecreatetruecolor($size_x, $size_y);
|
|
|
13 |
imagecopymerge($dest_img, $image->get_handle(), 0, 0, 0, 0, $size_x, $size_y, 100);
|
|
|
14 |
|
|
|
15 |
// initialize line length counter
|
|
|
16 |
$ctr = 0;
|
|
|
17 |
|
|
|
18 |
for ($y = 0; $y < $size_y; $y++) {
|
|
|
19 |
$line = "";
|
|
|
20 |
|
|
|
21 |
for ($x = 0; $x < $size_x; $x++) {
|
|
|
22 |
// Save image pixel to the stream data
|
|
|
23 |
$rgb = ImageColorAt($dest_img, $x, $y);
|
|
|
24 |
$r = ($rgb >> 16) & 0xFF;
|
|
|
25 |
$g = ($rgb >> 8) & 0xFF;
|
|
|
26 |
$b = $rgb & 0xFF;
|
|
|
27 |
$line .= sprintf("%02X%02X%02X",min(max($r,0),255),min(max($g,0),255),min(max($b,0),255));
|
|
|
28 |
|
|
|
29 |
// Increate the line length counter; check if stream line needs to be terminated
|
|
|
30 |
$ctr += 6;
|
|
|
31 |
if ($ctr > MAX_LINE_LENGTH) {
|
|
|
32 |
$line .= "\n";
|
|
|
33 |
$ctr = 0;
|
|
|
34 |
}
|
|
|
35 |
};
|
|
|
36 |
|
|
|
37 |
$lines[] = $line;
|
|
|
38 |
};
|
|
|
39 |
|
|
|
40 |
return $lines;
|
|
|
41 |
}
|
|
|
42 |
}
|
|
|
43 |
?>
|