Changeset 25754 for trunk/include/derivative_params.inc.php
- Timestamp:
- Nov 29, 2013, 2:48:55 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/derivative_params.inc.php
r20335 r25754 20 20 // +-----------------------------------------------------------------------+ 21 21 22 /** 23 * @package Derivatives 24 */ 25 26 27 /** 28 * Formats a size name into a 2 chars identifier usable in filename. 29 * 30 * @param string $t one of IMG_* 31 * @return string 32 */ 22 33 function derivative_to_url($t) 23 34 { … … 25 36 } 26 37 38 /** 39 * Formats a size array into a identifier usable in filename. 40 * 41 * @param int[] $s 42 * @return string 43 */ 27 44 function size_to_url($s) 28 45 { … … 34 51 } 35 52 53 /** 54 * @param int[] $s1 55 * @param int[] $s2 56 * @return bool 57 */ 36 58 function size_equals($s1, $s2) 37 59 { … … 39 61 } 40 62 63 /** 64 * Converts a char a-z into a float. 65 * 66 * @param string 67 * @return float 68 */ 41 69 function char_to_fraction($c) 42 70 { … … 44 72 } 45 73 74 /** 75 * Converts a float into a char a-z. 76 * 77 * @param float 78 * @return string 79 */ 46 80 function fraction_to_char($f) 47 81 { … … 49 83 } 50 84 51 /** small utility to manipulate a 'rectangle'*/ 85 86 /** 87 * Small utility to manipulate a 'rectangle'. 88 */ 52 89 final class ImageRect 53 90 { 91 /** 92 * @var int $l 93 * @var int $t 94 * @var int $r 95 * @var int $b 96 */ 54 97 public $l,$t,$r,$b; 55 98 99 /** 100 * @param int[] $l width and height 101 */ 56 102 function __construct($l) 57 103 { … … 61 107 } 62 108 109 /** 110 * @return int 111 */ 63 112 function width() 64 113 { … … 66 115 } 67 116 117 /** 118 * @return int 119 */ 68 120 function height() 69 121 { … … 71 123 } 72 124 73 /** crops horizontally this rectangle by increasing left side and/or reducing the right side. 74 @param pixels the amount to substract from the width 75 @param coi a 4 character string (or null) containing the center of interest*/ 125 /** 126 * Crops horizontally this rectangle by increasing left side and/or reducing the right side. 127 * 128 * @param int $pixels - the amount to substract from the width 129 * @param stirng $coi - a 4 character string (or null) containing the center of interest 130 */ 76 131 function crop_h($pixels, $coi) 77 132 { … … 102 157 } 103 158 104 /** crops vertically this rectangle by increasing top side and/or reducing the bottom side. 105 @param pixels the amount to substract from the height 106 @param coi a 4 character string (or null) containing the center of interest*/ 159 /** 160 * Crops vertically this rectangle by increasing top side and/or reducing the bottom side. 161 * 162 * @param int $pixels - the amount to substract from the height 163 * @param string $coi - a 4 character string (or null) containing the center of interest 164 */ 107 165 function crop_v($pixels, $coi) 108 166 { … … 132 190 $this->b -= $pixels - $tlcrop; 133 191 } 134 135 } 136 137 138 /** Paramaters for derivative scaling and cropping. Instance of this class contained by DerivativeParams class.*/ 192 } 193 194 195 /** 196 * Paramaters for derivative scaling and cropping. 197 * Instance of this class contained by DerivativeParams class. 198 */ 139 199 final class SizingParams 140 200 { 141 /** 142 @param ideal_size two element array of maximum output dimensions (width, height) 143 @param max_crop range 0=no cropping ... 1= max cropping (100% of width/height); expressed as a factor of the input width/height 144 @param min_size used only if max_crop != 0 - two element array of output dimensions (width, height) 145 */ 146 function __construct($ideal_size, $max_crop = 0, $min_size = null) 201 /** @var int[] */ 202 var $ideal_size; 203 /** @var float */ 204 var $max_crop; 205 /** @var int[] */ 206 var $min_size; 207 208 /** 209 * @param int[] $ideal_size - two element array of maximum output dimensions (width, height) 210 * @param float $max_crop - from 0=no cropping to 1= max cropping (100% of width/height); 211 * expressed as a factor of the input width/height 212 * @param int[] $min_size - (used only if _$max_crop_ !=0) two element array of output dimensions (width, height) 213 */ 214 function __construct($ideal_size, $max_crop=0, $min_size=null) 147 215 { 148 216 $this->ideal_size = $ideal_size; 149 $this->max_crop = $max_crop; // range 0=no cropping ... 1= max cropping (100% of width/height)217 $this->max_crop = $max_crop; 150 218 $this->min_size = $min_size; 151 219 } 152 220 221 /** 222 * Returns a simple SizingParams object. 223 * 224 * @param int $w 225 * @param int $h 226 * @return SizingParams 227 */ 153 228 static function classic($w, $h) 154 229 { … … 156 231 } 157 232 233 /** 234 * Returns a square SizingParams object. 235 * 236 * @param int $x 237 * @return SizingParams 238 */ 158 239 static function square($w) 159 240 { … … 161 242 } 162 243 244 /** 245 * Adds tokens depending on sizing configuration. 246 * 247 * @param array &$tokens 248 */ 163 249 function add_url_tokens(&$tokens) 164 250 { … … 179 265 } 180 266 181 /* calculate the cropping rectangle and the scaled size for an input image size 182 @param in_size two element array of input dimensions (width, height) 183 @param coi empty or a four character encoded string containing the center of interest (unused if max_crop=0) 184 @param crop_rect output ImageRect containing the cropping rectangle or null if cropping is not required 185 @param scale_size output two element array containing width and height of the scaled image 186 */ 267 /** 268 * Calculates the cropping rectangle and the scaled size for an input image size. 269 * 270 * @param int[] $in_size - two element array of input dimensions (width, height) 271 * @param string $coi - four character encoded string containing the center of interest (unused if max_crop=0) 272 * @param ImageRect &$crop_rect - ImageRect containing the cropping rectangle or null if cropping is not required 273 * @param int[] &$scale_size - two element array containing width and height of the scaled image 274 */ 187 275 function compute($in_size, $coi, &$crop_rect, &$scale_size) 188 276 { … … 246 334 } 247 335 } 248 249 } 250 251 252 /** All needed parameters to generate a derivative image.*/ 336 } 337 338 339 /** 340 * All needed parameters to generate a derivative image. 341 */ 253 342 final class DerivativeParams 254 343 { 255 public $type = IMG_CUSTOM; // string IMG_xxx 256 public $last_mod_time = 0; // used for non-custom images to regenerate the cached files 344 /** @var SizingParams */ 345 public $sizing; 346 /** @var string among IMG_* */ 347 public $type = IMG_CUSTOM; 348 /** @var int used for non-custom images to regenerate the cached files */ 349 public $last_mod_time = 0; 350 /** @var bool */ 257 351 public $use_watermark = false; 258 public $sizing; // of type SizingParams 259 public $sharpen = 0; // range 0= no sharpening ... 1= max sharpening 260 352 /** @var float from 0=no sharpening to 1=max sharpening */ 353 public $sharpen = 0; 354 355 /** 356 * @param SizingParams $sizing 357 */ 261 358 function __construct($sizing) 262 359 { … … 264 361 } 265 362 363 /** 364 * @return array 365 */ 266 366 public function __sleep() 267 367 { 268 return array('last_mod_time', 'sizing', 'sharpen'); 269 } 270 368 return array('last_mod_time', 'sizing', 'sharpen'); 369 } 370 371 /** 372 * Adds tokens depending on sizing configuration. 373 * 374 * @param array &$tokens 375 */ 271 376 function add_url_tokens(&$tokens) 272 377 { … … 274 379 } 275 380 381 /** 382 * @return int[] 383 */ 276 384 function compute_final_size($in_size) 277 385 { … … 280 388 } 281 389 390 /** 391 * @return int 392 */ 282 393 function max_width() 283 394 { … … 285 396 } 286 397 398 /** 399 * @return int 400 */ 287 401 function max_height() 288 402 { … … 290 404 } 291 405 406 /** 407 * @todo : description of DerivativeParams::is_identity 408 * 409 * @return bool 410 */ 292 411 function is_identity($in_size) 293 412 { … … 300 419 } 301 420 421 /** 422 * @return bool 423 */ 302 424 function will_watermark($out_size) 303 425 { … … 311 433 } 312 434 } 435 313 436 ?>
Note: See TracChangeset
for help on using the changeset viewer.