This repository was archived by the owner on Oct 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstructs.php
More file actions
63 lines (55 loc) · 1.31 KB
/
structs.php
File metadata and controls
63 lines (55 loc) · 1.31 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
62
63
<?php
class Rect
{
function __construct($x, $y, $w, $h)
{
$this->x = $x;
$this->y = $y;
$this->w = $w;
$this->h = $h;
}
var $x, $y, $w, $h;
}
function create_from($filename)
{
$type = exif_imagetype($filename);
switch ($type)
{
case IMAGETYPE_GIF: $handle = imagecreatefromgif($filename); break;
case IMAGETYPE_JPEG: $handle = imagecreatefromjpeg($filename); break;
case IMAGETYPE_PNG: $handle = imagecreatefrompng($filename); break;
}
return $handle;
}
class Image
{
function __construct($filename, $x = 0, $y = 0, $w = -1, $h = -1)
{
$this->filename = $filename;
$this->is_valid = true;
if ($filename !== null)
{
$this->handle = create_from($filename);
$rw = imagesx($this->handle);
$rh = imagesy($this->handle);
$this->rect = new Rect((int)$x, (int)$y, (int)$rw, (int)$rh);
}
else
{
$this->rect = new Rect((int)$x, (int)$y, (int)$w, (int)$h);
$this->handle = imagecreate($this->rect->w, $this->rect->h);
imagealphablending($this->handle, true);
$white = imagecolorallocate($this->handle, 255, 255, 255);
imagefill($this->handle, 0, 0, $white);
}
if ($this->handle === false)
{
$this->is_valid = false;
return;
}
}
var $filename;
var $rect;
var $handle;
var $is_valid;
}