source: trunk/include/derivative_std_params.inc.php @ 12796

Last change on this file since 12796 was 12796, checked in by rvelices, 9 years ago

feature 2541 multisize

  • core implementation + usage on most public/admin pages
  • still to do: sync process, upload, gui/persistence for size parameters, migration script, center of interest ...
File size: 3.8 KB
Line 
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
22define('IMG_SQUARE', 'square');
23define('IMG_THUMB', 'thumb');
24define('IMG_SMALL', 'small');
25define('IMG_MEDIUM', 'medium');
26define('IMG_LARGE', 'large');
27define('IMG_XLARGE', 'xlarge');
28define('IMG_XXLARGE', 'xxlarge');
29define('IMG_CUSTOM', 'custom');
30
31final class ImageStdParams
32{
33  private static $all_types = array(IMG_SQUARE,IMG_THUMB,IMG_SMALL,IMG_MEDIUM,IMG_LARGE,IMG_XLARGE,IMG_XXLARGE);
34  private static $all_type_map = array();
35  private static $type_map = array();
36  private static $undefined_type_map = array();
37 
38  static function get_all_types()
39  {
40    return self::$all_types;
41  }
42 
43  static function get_all_type_map()
44  {
45    return self::$all_type_map;
46  }
47
48  static function get_defined_type_map()
49  {
50    return self::$type_map;
51  }
52
53  static function get_undefined_type_map()
54  {
55    return self::$undefined_type_map;
56  }
57 
58  static function get_by_type($type)
59  {
60    return self::$all_type_map[$type];
61  }
62 
63  static function load_from_db()
64  {
65    self::make_default();
66    self::build_maps();
67  }
68
69  static function load_from_file()
70  {
71    self::make_default();
72    self::build_maps();
73  }
74
75  static function make_default()
76  {
77    //todo
78    self::$type_map[IMG_SQUARE] = new ImageParams( SizingParams::square(100,100) );
79    self::$type_map[IMG_THUMB] = new ImageParams( SizingParams::classic(144,144) );
80    self::$type_map[IMG_SMALL] = new ImageParams( SizingParams::classic(240,240) );
81    self::$type_map[IMG_MEDIUM] = new ImageParams( SizingParams::classic(432,432) );
82    self::$type_map[IMG_LARGE] = new ImageParams( SizingParams::classic(648,576) );
83    self::$type_map[IMG_XLARGE] = new ImageParams( SizingParams::classic(864,648) );
84    self::$type_map[IMG_XXLARGE] = new ImageParams( SizingParams::classic(1200,900) );
85  }
86 
87  private static function build_maps()
88  {
89    foreach (self::$type_map as $type=>$params)
90    {
91      $params->type = $type;
92    }
93    self::$all_type_map = self::$type_map;
94
95    for ($i=0; $i<count(self::$all_types); $i++)
96    {
97      $tocheck = self::$all_types[$i];
98      if (!isset(self::$type_map[$tocheck]))
99      {
100        for ($j=$i-1; $j>=0; $j--)
101        {
102          $target = self::$all_types[$j];
103          if (isset(self::$type_map[$target]))
104          {
105            self::$all_type_map[$tocheck] = self::$type_map[$target];
106            self::$undefined_type_map[$tocheck] = $target;
107            break;
108          }
109        }
110      }
111    }
112  }
113 
114}
115
116?>
Note: See TracBrowser for help on using the repository browser.