1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Wraps a special case that really only occurs when we try to |
4
|
|
|
* generate a thumbnail from a missing image (remote and local). |
5
|
|
|
* |
6
|
|
|
* @author Mark Guinn <[email protected]> |
7
|
|
|
* @date 03.03.2014 |
8
|
|
|
* @package cloudassets |
9
|
|
|
* @subpackage wrappers |
10
|
|
|
*/ |
11
|
|
|
class CloudImageMissing extends Image |
12
|
|
|
{ |
13
|
|
|
/** @var CloudImage */ |
14
|
|
|
protected $source; |
15
|
|
|
|
16
|
|
|
/** @var string - e.g. 1x1 */ |
17
|
|
|
protected $dimensions; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Create a new cached image. |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
public function __construct($source=null, $args=null) |
25
|
|
|
{ |
26
|
|
|
parent::__construct(array(), false); |
27
|
|
|
$this->ID = -1; |
28
|
|
|
$this->Filename = CloudAssets::config()->missing_image; |
29
|
|
|
$this->source = $source; |
30
|
|
|
if (empty($args)) { |
31
|
|
|
$this->dimensions = '100x100'; |
32
|
|
|
} else { |
33
|
|
|
switch ($args[0]) { |
34
|
|
|
case 'SetWidth'; |
35
|
|
|
case 'SetHeight': |
36
|
|
|
case 'ScaleWidth': |
37
|
|
|
case 'ScaleHeight': |
38
|
|
|
$this->dimensions = $args[1] . 'x' . $args[1]; |
39
|
|
|
break; |
40
|
|
|
|
41
|
|
|
case 'SetSize'; |
42
|
|
|
case 'SetRatioSize'; |
43
|
|
|
case 'ResizedImage'; |
44
|
|
|
case 'CroppedImage'; |
45
|
|
|
case 'PaddedImage': |
46
|
|
|
$this->dimensions = $args[1] . 'x' . $args[2]; |
47
|
|
|
break; |
48
|
|
|
|
49
|
|
|
default: |
50
|
|
|
$this->dimensions = '100x100'; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return String |
58
|
|
|
*/ |
59
|
|
|
public function getRelativePath() |
60
|
|
|
{ |
61
|
|
|
return $this->getField('Filename'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Prevent creating new tables for the cached record |
67
|
|
|
* |
68
|
|
|
* @return false |
69
|
|
|
*/ |
70
|
|
|
public function requireTable() |
71
|
|
|
{ |
72
|
|
|
return false; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Prevent writing the cached image to the database, but write the store record instead |
78
|
|
|
*/ |
79
|
|
|
public function write($showDebug = false, $forceInsert = false, $forceWrite = false, $writeComponents = false) |
80
|
|
|
{ |
81
|
|
|
throw new Exception("{$this->ClassName} can not be written back to the database."); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Prevent a delete |
87
|
|
|
*/ |
88
|
|
|
public function delete() |
89
|
|
|
{ |
90
|
|
|
throw new Exception("{$this->ClassName} can not be written back to the database."); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $dim - 'string' or 0 (width) or 1 (height) |
96
|
|
|
* @return int|string |
97
|
|
|
*/ |
98
|
|
|
public function getDimensions($dim = "string") |
99
|
|
|
{ |
100
|
|
|
$val = $this->dimensions; |
101
|
|
|
if ($dim === 'string') { |
102
|
|
|
return $val; |
103
|
|
|
} |
104
|
|
|
$val = explode('x', $val); |
105
|
|
|
return $val[$dim]; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|