-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimagewatermark.class
More file actions
61 lines (45 loc) · 1.51 KB
/
Copy pathimagewatermark.class
File metadata and controls
61 lines (45 loc) · 1.51 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
60
61
<?php
class ImageWatermark {
private $IR;
private $Wm_Res;
private $Resized;
public $OffsetX;
public $OffsetY;
public function __construct($watermark_file) {
$this->IR = new ImageResize();
$this->IR->OutputFormat = ImageResize::IMAGETYPE_GD;
$this->Wm_Res = $this->IR->LoadFromFile($watermark_file);
$this->Resized = false;
}
public function __destroy() {
$this->IR->FreeResource($this->Wm_Res);
}
public function SetWidth($width) {
$this->Resized = true;
$this->IR->SetWidth($width);
}
public function SetHeight($height) {
$this->Resized = true;
$this->IR->SetHeight($height);
}
public function SetOffsetX($offset_x) {
$this->OffsetX = $offset_x;
}
public function SetOffsetY($offset_y) {
$this->OffsetY = $offset_y;
}
// XXX: Currently only supports placing watermarks in the lower right corner
public function Watermark($gd_image_resource) {
if ($this->Resized == true) {
$this->Wm_Res = $this->IR->Resize($this->Wm_Res);
$this->Resized = false;
}
$wm_width = imagesx($this->Wm_Res);
$wm_height = imagesy($this->Wm_Res);
$img_width = imagesx($gd_image_resource);
$img_height = imagesy($gd_image_resource);
imagecopy($gd_image_resource, $this->Wm_Res, $img_width-($wm_width+$this->OffsetX),
($img_height-$wm_height)+OffsetY, 0, 0, $wm_width, $wm_height);
}
}
?>