-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitmap.php
More file actions
59 lines (44 loc) · 1.36 KB
/
Copy pathBitmap.php
File metadata and controls
59 lines (44 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace LazyBitmap;
use LazyBitmap\ILazyBitmap;
abstract class Bitmap implements ILazyBitmap {
protected $lbm;
public function __construct(ILazyBitmap $lbm) {
$this->lbm = $lbm;
}
public function getPixel($x, $y) {
return $this->lbm->getPixel($x, $y);
}
public function getWidth() {
return $this->lbm->getWidth();
}
public function getHeight() {
return $this->lbm->getHeight();
}
public function getImage() {
$image = imagecreatetruecolor($this->getWidth(), $this->getHeight());
imagesavealpha($image, true);
imagefill($image, 0, 0, imagecolorallocatealpha($image, 0, 0, 0, 127));
for ($y = 0; $y < $this->getHeight(); $y++) {
for ($x = 0; $x < $this->getWidth(); $x++) {
$pixel = $this->getPixel($x, $y);
if (!$pixel->isActive()) {
continue;
}
imagesetpixel($image, $x, $y, $pixel->getColor($image));
}
}
return $image;
}
public function render() {
$image = $this->getImage();
header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
}
public function save($file) {
$image = $this->getImage();
imagepng($image, $file);
imagedestroy($image);
}
}