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

Last change on this file since 12820 was 12820, checked in by rvelices, 12 years ago

feature 2541 multisize

  • admin GUI for choosing derivative parameters + persistence
File size: 4.5 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    global $conf;
66    $arr = @unserialize($conf['derivatives']);
67    if (false!==$arr)
68    {
69      self::$type_map = $arr['d'];
70    }
71    else
72    {
73      self::make_default();
74    }
75    self::build_maps();
76  }
77
78  static function load_from_file()
79  {
80    global $conf;
81    $arr = @unserialize(@file_get_contents(PHPWG_ROOT_PATH.$conf['data_location'].'derivatives.dat'));
82    if (false!==$arr)
83    {
84      self::$type_map = $arr['d'];
85    }
86    else
87    {
88      self::make_default();
89    }
90    self::build_maps();
91  }
92
93  static function set_and_save($map)
94  {
95    global $conf;
96    self::$type_map = $map;
97
98    $ser = serialize( array(
99      'd' => self::$type_map
100      ) );
101    conf_update_param('derivatives', addslashes($ser) );
102    file_put_contents(PHPWG_ROOT_PATH.$conf['data_location'].'derivatives.dat', $ser);
103    self::build_maps();
104  }
105
106  static function make_default()
107  {
108    self::$type_map[IMG_SQUARE] = new DerivativeParams( SizingParams::square(100,100) );
109    self::$type_map[IMG_THUMB] = new DerivativeParams( SizingParams::classic(144,144) );
110    self::$type_map[IMG_SMALL] = new DerivativeParams( SizingParams::classic(240,240) );
111    self::$type_map[IMG_MEDIUM] = new DerivativeParams( SizingParams::classic(432,432) );
112    self::$type_map[IMG_LARGE] = new DerivativeParams( SizingParams::classic(648,576) );
113    self::$type_map[IMG_XLARGE] = new DerivativeParams( SizingParams::classic(864,648) );
114    self::$type_map[IMG_XXLARGE] = new DerivativeParams( SizingParams::classic(1200,900) );
115  }
116
117  private static function build_maps()
118  {
119    foreach (self::$type_map as $type=>$params)
120    {
121      $params->type = $type;
122    }
123    self::$all_type_map = self::$type_map;
124
125    for ($i=0; $i<count(self::$all_types); $i++)
126    {
127      $tocheck = self::$all_types[$i];
128      if (!isset(self::$type_map[$tocheck]))
129      {
130        for ($j=$i-1; $j>=0; $j--)
131        {
132          $target = self::$all_types[$j];
133          if (isset(self::$type_map[$target]))
134          {
135            self::$all_type_map[$tocheck] = self::$type_map[$target];
136            self::$undefined_type_map[$tocheck] = $target;
137            break;
138          }
139        }
140      }
141    }
142  }
143
144}
145
146?>
Note: See TracBrowser for help on using the repository browser.