|
1
|
|
|
<?php
|
|
2
|
|
|
|
|
3
|
|
|
namespace Swader\Diffbot\Entity;
|
|
4
|
|
|
|
|
5
|
|
|
use Swader\Diffbot\Abstracts\Entity;
|
|
6
|
|
|
use Swader\Diffbot\Traits\StandardEntity;
|
|
7
|
|
|
|
|
8
|
|
|
class Image extends Entity
|
|
9
|
|
|
{
|
|
10
|
|
|
use StandardEntity;
|
|
11
|
|
|
|
|
12
|
|
|
/**
|
|
13
|
|
|
* Should always return "image"
|
|
14
|
|
|
* @return string
|
|
15
|
|
|
*/
|
|
16
|
3 |
|
public function getType()
|
|
17
|
|
|
{
|
|
18
|
3 |
|
return $this->data['type'];
|
|
19
|
|
|
}
|
|
20
|
|
|
|
|
21
|
|
|
/**
|
|
22
|
|
|
* Height of image as (re-)sized via browser/CSS.
|
|
23
|
|
|
* @return mixed
|
|
24
|
|
|
*/
|
|
25
|
2 |
|
public function getHeight()
|
|
26
|
|
|
{
|
|
27
|
2 |
|
return (isset($this->data['height']))
|
|
28
|
2 |
|
? $this->data['height'] : $this->getNaturalHeight();
|
|
29
|
|
|
}
|
|
30
|
|
|
|
|
31
|
|
|
/**
|
|
32
|
|
|
* Width of image as (re-)sized via browser/CSS.
|
|
33
|
|
|
* @return mixed
|
|
34
|
|
|
*/
|
|
35
|
2 |
|
public function getWidth()
|
|
36
|
|
|
{
|
|
37
|
2 |
|
return (isset($this->data['width']))
|
|
38
|
2 |
|
? $this->data['width'] : $this->getNaturalWidth();
|
|
39
|
|
|
}
|
|
40
|
|
|
|
|
41
|
|
|
/**
|
|
42
|
|
|
* Raw image height, in pixels.
|
|
43
|
|
|
* @return mixed
|
|
44
|
|
|
*/
|
|
45
|
4 |
|
public function getNaturalHeight()
|
|
46
|
|
|
{
|
|
47
|
4 |
|
return $this->data['naturalHeight'];
|
|
48
|
|
|
}
|
|
49
|
|
|
|
|
50
|
|
|
/**
|
|
51
|
|
|
* Raw image width, in pixels.
|
|
52
|
|
|
* @return mixed
|
|
53
|
|
|
*/
|
|
54
|
4 |
|
public function getNaturalWidth()
|
|
55
|
|
|
{
|
|
56
|
4 |
|
return $this->data['naturalWidth'];
|
|
57
|
|
|
}
|
|
58
|
|
|
|
|
59
|
|
|
/**
|
|
60
|
|
|
* Returns the URL of the image
|
|
61
|
|
|
* @return string
|
|
62
|
|
|
*/
|
|
63
|
2 |
|
public function getUrl()
|
|
64
|
|
|
{
|
|
65
|
2 |
|
return $this->data['url'];
|
|
66
|
|
|
}
|
|
67
|
|
|
|
|
68
|
|
|
/**
|
|
69
|
|
|
* Returns the URL to which the image is linked, if any. Otherwise, null.
|
|
70
|
|
|
* @return string|null
|
|
71
|
|
|
*/
|
|
72
|
2 |
|
public function getAnchorUrl()
|
|
73
|
|
|
{
|
|
74
|
2 |
|
return (isset($this->data['anchorUrl']))
|
|
75
|
2 |
|
? $this->data['anchorUrl'] : null;
|
|
76
|
|
|
}
|
|
77
|
|
|
|
|
78
|
|
|
/**
|
|
79
|
|
|
* XPath Expression identifying the image node in the page
|
|
80
|
|
|
* @return string
|
|
81
|
|
|
*/
|
|
82
|
2 |
|
public function getXPath()
|
|
83
|
|
|
{
|
|
84
|
2 |
|
return $this->data['xpath'];
|
|
85
|
|
|
}
|
|
86
|
|
|
|
|
87
|
|
|
/**
|
|
88
|
|
|
* Returns an array of [title, link] arrays for all posts where this image,
|
|
89
|
|
|
* or a similar one, was found
|
|
90
|
|
|
* @return array
|
|
91
|
|
|
*/
|
|
92
|
2 |
|
public function getMentions()
|
|
93
|
|
|
{
|
|
94
|
2 |
|
$d = $this->data;
|
|
95
|
|
|
|
|
96
|
2 |
|
return (isset($d['mentions']) && !empty($d['mentions']))
|
|
97
|
2 |
|
? $d['mentions'] : [];
|
|
98
|
|
|
}
|
|
99
|
|
|
|
|
100
|
|
|
/**
|
|
101
|
|
|
* Returns recognized faces
|
|
102
|
|
|
* Currently doesn't even recognize Oprah, heavy beta, do not use
|
|
103
|
|
|
* @return string
|
|
104
|
|
|
*/
|
|
105
|
2 |
|
public function getFaces()
|
|
106
|
|
|
{
|
|
107
|
2 |
|
$d = $this->data;
|
|
108
|
|
|
|
|
109
|
2 |
|
return (isset($d['faces']) && !empty($d['faces']))
|
|
110
|
2 |
|
? $d['faces'] : "";
|
|
111
|
|
|
}
|
|
112
|
|
|
|
|
113
|
|
|
/**
|
|
114
|
|
|
* Returns recognized text from picture
|
|
115
|
|
|
* Currently does not recognize anything, heavy beta, do not use
|
|
116
|
|
|
* @return string
|
|
117
|
|
|
*/
|
|
118
|
2 |
|
public function getOcr()
|
|
119
|
|
|
{
|
|
120
|
2 |
|
return (isset($this->data['ocr']) && !empty($this->data['ocr']))
|
|
121
|
2 |
|
? $this->data['ocr'] : "";
|
|
122
|
|
|
}
|
|
123
|
|
|
} |