1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | This program is free software; you can redistribute it and/or modify | |
---|
8 | // | it under the terms of the GNU General Public License as published by | |
---|
9 | // | the Free Software Foundation | |
---|
10 | // | | |
---|
11 | // | This program is distributed in the hope that it will be useful, but | |
---|
12 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
13 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
14 | // | General Public License for more details. | |
---|
15 | // | | |
---|
16 | // | You should have received a copy of the GNU General Public License | |
---|
17 | // | along with this program; if not, write to the Free Software | |
---|
18 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
19 | // | USA. | |
---|
20 | // +-----------------------------------------------------------------------+ |
---|
21 | |
---|
22 | define('IMG_SQUARE', 'square'); |
---|
23 | define('IMG_THUMB', 'thumb'); |
---|
24 | define('IMG_SMALL', 'small'); |
---|
25 | define('IMG_MEDIUM', 'medium'); |
---|
26 | define('IMG_LARGE', 'large'); |
---|
27 | define('IMG_XLARGE', 'xlarge'); |
---|
28 | define('IMG_XXLARGE', 'xxlarge'); |
---|
29 | define('IMG_CUSTOM', 'custom'); |
---|
30 | |
---|
31 | final class WatermarkParams |
---|
32 | { |
---|
33 | public $file = ''; |
---|
34 | public $min_size = array(500,500); |
---|
35 | public $xpos = 50; |
---|
36 | public $ypos = 50; |
---|
37 | public $xrepeat = 0; |
---|
38 | public $opacity = 100; |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | final class ImageStdParams |
---|
43 | { |
---|
44 | private static $all_types = array(IMG_SQUARE,IMG_THUMB,IMG_SMALL,IMG_MEDIUM,IMG_LARGE,IMG_XLARGE,IMG_XXLARGE); |
---|
45 | private static $all_type_map = array(); |
---|
46 | private static $type_map = array(); |
---|
47 | private static $undefined_type_map = array(); |
---|
48 | private static $watermark; |
---|
49 | |
---|
50 | static function get_all_types() |
---|
51 | { |
---|
52 | return self::$all_types; |
---|
53 | } |
---|
54 | |
---|
55 | static function get_all_type_map() |
---|
56 | { |
---|
57 | return self::$all_type_map; |
---|
58 | } |
---|
59 | |
---|
60 | static function get_defined_type_map() |
---|
61 | { |
---|
62 | return self::$type_map; |
---|
63 | } |
---|
64 | |
---|
65 | static function get_undefined_type_map() |
---|
66 | { |
---|
67 | return self::$undefined_type_map; |
---|
68 | } |
---|
69 | |
---|
70 | static function get_by_type($type) |
---|
71 | { |
---|
72 | return self::$all_type_map[$type]; |
---|
73 | } |
---|
74 | |
---|
75 | static function get_watermark() |
---|
76 | { |
---|
77 | return self::$watermark; |
---|
78 | } |
---|
79 | |
---|
80 | static function load_from_db() |
---|
81 | { |
---|
82 | global $conf; |
---|
83 | $arr = @unserialize($conf['derivatives']); |
---|
84 | if (false!==$arr) |
---|
85 | { |
---|
86 | self::$type_map = $arr['d']; |
---|
87 | self::$watermark = @$arr['w']; |
---|
88 | if (!self::$watermark) self::$watermark = new WatermarkParams(); |
---|
89 | } |
---|
90 | else |
---|
91 | { |
---|
92 | self::make_default(); |
---|
93 | } |
---|
94 | self::build_maps(); |
---|
95 | } |
---|
96 | |
---|
97 | static function load_from_file() |
---|
98 | { |
---|
99 | global $conf; |
---|
100 | $arr = @unserialize(@file_get_contents(PHPWG_ROOT_PATH.$conf['data_location'].'derivatives.dat')); |
---|
101 | if (false!==$arr) |
---|
102 | { |
---|
103 | self::$type_map = $arr['d']; |
---|
104 | self::$watermark = @$arr['w']; |
---|
105 | if (!self::$watermark) self::$watermark = new WatermarkParams(); |
---|
106 | } |
---|
107 | else |
---|
108 | { |
---|
109 | self::make_default(); |
---|
110 | } |
---|
111 | self::build_maps(); |
---|
112 | } |
---|
113 | |
---|
114 | static function set_watermark($watermark) |
---|
115 | { |
---|
116 | self::$watermark = $watermark; |
---|
117 | } |
---|
118 | |
---|
119 | static function set_and_save($map) |
---|
120 | { |
---|
121 | global $conf; |
---|
122 | self::$type_map = $map; |
---|
123 | |
---|
124 | $ser = serialize( array( |
---|
125 | 'd' => self::$type_map, |
---|
126 | 'w' => self::$watermark, |
---|
127 | ) ); |
---|
128 | conf_update_param('derivatives', addslashes($ser) ); |
---|
129 | file_put_contents(PHPWG_ROOT_PATH.$conf['data_location'].'derivatives.dat', $ser); |
---|
130 | self::build_maps(); |
---|
131 | } |
---|
132 | |
---|
133 | private static function make_default() |
---|
134 | { |
---|
135 | self::$watermark = new WatermarkParams(); |
---|
136 | self::$type_map[IMG_SQUARE] = new DerivativeParams( SizingParams::square(100,100) ); |
---|
137 | self::$type_map[IMG_THUMB] = new DerivativeParams( SizingParams::classic(144,144) ); |
---|
138 | self::$type_map[IMG_SMALL] = new DerivativeParams( SizingParams::classic(240,240) ); |
---|
139 | self::$type_map[IMG_MEDIUM] = new DerivativeParams( SizingParams::classic(432,432) ); |
---|
140 | self::$type_map[IMG_LARGE] = new DerivativeParams( SizingParams::classic(648,576) ); |
---|
141 | self::$type_map[IMG_XLARGE] = new DerivativeParams( SizingParams::classic(864,648) ); |
---|
142 | self::$type_map[IMG_XXLARGE] = new DerivativeParams( SizingParams::classic(1200,900) ); |
---|
143 | } |
---|
144 | |
---|
145 | public static function apply_global($params) |
---|
146 | { |
---|
147 | if (!empty(self::$watermark->file) && |
---|
148 | (self::$watermark->min_size[0]<=$params->sizing->ideal_size[0] |
---|
149 | && self::$watermark->min_size[1]<=$params->sizing->ideal_size[1] ) ) |
---|
150 | { |
---|
151 | $params->use_watermark = true; |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | private static function build_maps() |
---|
156 | { |
---|
157 | foreach (self::$type_map as $type=>$params) |
---|
158 | { |
---|
159 | $params->type = $type; |
---|
160 | self::apply_global($params); |
---|
161 | } |
---|
162 | self::$all_type_map = self::$type_map; |
---|
163 | |
---|
164 | for ($i=0; $i<count(self::$all_types); $i++) |
---|
165 | { |
---|
166 | $tocheck = self::$all_types[$i]; |
---|
167 | if (!isset(self::$type_map[$tocheck])) |
---|
168 | { |
---|
169 | for ($j=$i-1; $j>=0; $j--) |
---|
170 | { |
---|
171 | $target = self::$all_types[$j]; |
---|
172 | if (isset(self::$type_map[$target])) |
---|
173 | { |
---|
174 | self::$all_type_map[$tocheck] = self::$type_map[$target]; |
---|
175 | self::$undefined_type_map[$tocheck] = $target; |
---|
176 | break; |
---|
177 | } |
---|
178 | } |
---|
179 | } |
---|
180 | } |
---|
181 | } |
---|
182 | |
---|
183 | } |
---|
184 | |
---|
185 | ?> |
---|