Changeset 25754
- Timestamp:
- Nov 29, 2013, 2:48:55 PM (11 years ago)
- Location:
- trunk/include
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/derivative.inc.php
r25504 r25754 20 20 // +-----------------------------------------------------------------------+ 21 21 22 /*A source image is used to get a derivative image. A source image is either the original file for a jpg or a 23 'representative' image of a non image file or a standard icon for the non-image file.*/ 22 /** 23 * @package Derivatives 24 */ 25 26 27 /** 28 * A source image is used to get a derivative image. It is either 29 * the original file for a jpg/png/... or a 'representative' image 30 * of a non image file or a standard icon for the non-image file. 31 */ 24 32 final class SrcImage 25 33 { … … 28 36 const DIM_NOT_GIVEN = 0x04; 29 37 38 /** @var int */ 30 39 public $id; 40 /** @var string */ 31 41 public $rel_path; 42 /** @var int */ 32 43 public $rotation = 0; 33 44 /** @var int[] */ 34 45 private $size=null; 46 /** @var int */ 35 47 private $flags=0; 36 48 37 /*@param infos assoc array of data from images table*/ 49 /** 50 * @param array $infos assoc array of data from images table 51 */ 38 52 function __construct($infos) 39 53 { … … 89 103 } 90 104 105 /** 106 * @return bool 107 */ 91 108 function is_original() 92 109 { … … 94 111 } 95 112 113 /** 114 * @return bool 115 */ 96 116 function is_mimetype() 97 117 { … … 99 119 } 100 120 121 /** 122 * @return string 123 */ 101 124 function get_path() 102 125 { … … 104 127 } 105 128 129 /** 130 * @return string 131 */ 106 132 function get_url() 107 133 { … … 114 140 } 115 141 142 /** 143 * @return bool 144 */ 116 145 function has_size() 117 146 { … … 119 148 } 120 149 121 /* @return a 2-element array containing width/height or null if dimensions are not available*/ 150 /** 151 * @return int[]|null 0=width, 1=height or null if fail to compute size 152 */ 122 153 function get_size() 123 154 { … … 138 169 139 170 140 /*Holds information (path, url, dimensions) about a derivative image. A derivative image is constructed from a source 141 image (SrcImage class) and derivative parameters (DerivativeParams class). 142 */ 171 /** 172 * Holds information (path, url, dimensions) about a derivative image. 173 * A derivative image is constructed from a source image (SrcImage class) 174 * and derivative parameters (DerivativeParams class). 175 */ 143 176 final class DerivativeImage 144 177 { 178 /** @var SrcImage */ 145 179 public $src_image; 146 180 /** @var array */ 147 181 private $params; 148 private $rel_path, $rel_url, $is_cached=true; 149 150 /* 151 @param type string of standard derivative param type (e.g. IMG_???) or a DerivativeParams object 152 @param src_image the source image of this derivative*/ 182 /** @var string */ 183 private $rel_path; 184 /** @var string */ 185 private $rel_url; 186 /** @var bool */ 187 private $is_cached=true; 188 189 /** 190 * @param string|DerivativeParams $type standard derivative param type (e.g. IMG_*) 191 * or a DerivativeParams object 192 * @param SrcImage $src_image the source image of this derivative 193 */ 153 194 function __construct($type, SrcImage $src_image) 154 195 { … … 166 207 } 167 208 209 /** 210 * Generates the url of a thumbnail. 211 * 212 * @param array|SrcImage $infos array of info from db or SrcImage 213 * @return string 214 */ 168 215 static function thumb_url($infos) 169 216 { … … 172 219 173 220 /** 174 @return derivative image url 175 @param type string of standard derivative param type (e.g. IMG_???) or a DerivativeParams object 176 @param infos assoc array of data from images table or a SrcImage object 177 */ 221 * Generates the url for a particular photo size. 222 * 223 * @param string|DerivativeParams $type standard derivative param type (e.g. IMG_*) 224 * or a DerivativeParams object 225 * @param array|SrcImage $infos array of info from db or SrcImage 226 * @return string 227 */ 178 228 static function url($type, $infos) 179 229 { … … 194 244 /** 195 245 * Return associative an array of all DerivativeImage for a specific image. 196 * Disabled derivative types can be still found in the return mapped to an246 * Disabled derivative types can be still found in the return, mapped to an 197 247 * enabled derivative (e.g. the values are not unique in the return array). 198 248 * This is useful for any plugin/theme to just use $deriv[IMG_XLARGE] even if … … 229 279 * Disabled derivatives fallback to an enabled derivative. 230 280 * 231 * @param string $type 281 * @param string $type standard derivative param type (e.g. IMG_*) 232 282 * @param array|SrcImage $src_image array of info from db or SrcImage 233 283 * @return DerivativeImage|null null if $type not found … … 255 305 } 256 306 307 /** 308 * @todo : documentation of DerivativeImage::build 309 */ 257 310 private static function build($src, &$params, &$rel_path, &$rel_url, &$is_cached=null) 258 311 { … … 335 388 } 336 389 390 /** 391 * @return string 392 */ 337 393 function get_path() 338 394 { … … 340 396 } 341 397 398 /** 399 * @return string 400 */ 342 401 function get_url() 343 402 { … … 353 412 } 354 413 414 /** 415 * @return bool 416 */ 355 417 function same_as_source() 356 418 { … … 358 420 } 359 421 360 422 /** 423 * @return string one if IMG_* or 'Original' 424 */ 361 425 function get_type() 362 426 { … … 366 430 } 367 431 368 /* returns the size of the derivative image*/ 432 /** 433 * @return int[] 434 */ 369 435 function get_size() 370 436 { … … 376 442 } 377 443 444 /** 445 * Returns the size as CSS rule. 446 * 447 * @return string 448 */ 378 449 function get_size_css() 379 450 { … … 385 456 } 386 457 458 /** 459 * Returns the size as HTML attributes. 460 * 461 * @return string 462 */ 387 463 function get_size_htm() 388 464 { … … 394 470 } 395 471 472 /** 473 * Returns literal size: $widthx$height. 474 * 475 * @return string 476 */ 396 477 function get_size_hr() 397 478 { … … 403 484 } 404 485 486 /** 487 * @param int $maxw 488 * @param int $mawh 489 * @return int[] 490 */ 405 491 function get_scaled_size($maxw, $maxh) 406 492 { … … 427 513 } 428 514 515 /** 516 * Returns the scaled size as HTML attributes. 517 * 518 * @param int $maxw 519 * @param int $mawh 520 * @return string 521 */ 429 522 function get_scaled_size_htm($maxw=9999, $maxh=9999) 430 523 { … … 436 529 } 437 530 531 /** 532 * @return bool 533 */ 438 534 function is_cached() 439 535 { -
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 ?> -
trunk/include/derivative_std_params.inc.php
r19703 r25754 20 20 // +-----------------------------------------------------------------------+ 21 21 22 /** 23 * @package Derivatives 24 */ 25 26 22 27 define('IMG_SQUARE', 'square'); 23 28 define('IMG_THUMB', 'thumb'); … … 31 36 define('IMG_CUSTOM', 'custom'); 32 37 38 39 /** 40 * Container for watermark configuration. 41 */ 33 42 final class WatermarkParams 34 43 { 44 /** @var string */ 35 45 public $file = ''; 46 /** @var int[] */ 36 47 public $min_size = array(500,500); 48 /** @var int */ 37 49 public $xpos = 50; 50 /** @var int */ 38 51 public $ypos = 50; 52 /** @var int */ 39 53 public $xrepeat = 0; 54 /** @var int */ 40 55 public $opacity = 100; 41 56 } 42 57 43 58 59 /** 60 * Container for standard derivatives parameters. 61 */ 44 62 final class ImageStdParams 45 63 { 64 /** @var string[] */ 46 65 private static $all_types = array( 47 IMG_SQUARE,IMG_THUMB,IMG_XXSMALL,IMG_XSMALL,IMG_SMALL,IMG_MEDIUM,IMG_LARGE,IMG_XLARGE,IMG_XXLARGE 66 IMG_SQUARE, IMG_THUMB, IMG_XXSMALL, IMG_XSMALL, IMG_SMALL, 67 IMG_MEDIUM, IMG_LARGE, IMG_XLARGE, IMG_XXLARGE 48 68 ); 69 /** @var DerivativeParams[] */ 49 70 private static $all_type_map = array(); 71 /** @var DerivativeParams[] */ 50 72 private static $type_map = array(); 73 /** @var DerivativeParams[] */ 51 74 private static $undefined_type_map = array(); 75 /** @var WatermarkParams */ 52 76 private static $watermark; 77 /** @var array */ 53 78 public static $custom = array(); 79 /** @var int */ 54 80 public static $quality=95; 55 81 82 /** 83 * @return string[] 84 */ 56 85 static function get_all_types() 57 86 { … … 59 88 } 60 89 90 /** 91 * @return DerivativeParams[] 92 */ 61 93 static function get_all_type_map() 62 94 { … … 64 96 } 65 97 98 /** 99 * @return DerivativeParams[] 100 */ 66 101 static function get_defined_type_map() 67 102 { … … 69 104 } 70 105 106 /** 107 * @return DerivativeParams[] 108 */ 71 109 static function get_undefined_type_map() 72 110 { … … 74 112 } 75 113 114 /** 115 * @return DerivativeParams 116 */ 76 117 static function get_by_type($type) 77 118 { … … 79 120 } 80 121 122 /** 123 * @param int $w 124 * @param int $h 125 * @param float $crop 126 * @param int $minw 127 * @param int $minh 128 * @return DerivativeParams 129 */ 81 130 static function get_custom($w, $h, $crop=0, $minw=null, $minh=null) 82 131 { … … 95 144 } 96 145 146 /** 147 * @return WatermarkParams 148 */ 97 149 static function get_watermark() 98 150 { … … 100 152 } 101 153 154 /** 155 * Loads derivative configuration from database or initializes it. 156 */ 102 157 static function load_from_db() 103 158 { … … 122 177 } 123 178 179 /** 180 * @param WatermarkParams $watermark 181 */ 124 182 static function set_watermark($watermark) 125 183 { … … 127 185 } 128 186 187 /** 188 * @see ImageStdParams::save() 189 * 190 * @param DerivativeParams[] $map 191 */ 129 192 static function set_and_save($map) 130 193 { … … 134 197 } 135 198 199 /** 200 * Saves the configuration in database. 201 */ 136 202 static function save() 137 203 { … … 147 213 } 148 214 215 /** 216 * @return DerivativeParams[] 217 */ 149 218 static function get_default_sizes() 150 219 { … … 160 229 IMG_XXLARGE => new DerivativeParams( SizingParams::classic(1656,1242) ), 161 230 ); 231 $now = time(); 162 232 foreach($arr as $params) 163 233 { 164 $params->last_mod_time = time();234 $params->last_mod_time = $now; 165 235 } 166 236 return $arr; 167 237 } 168 238 239 /** 240 * Compute 'apply_watermark' 241 * 242 * @param DerivativeParams $params 243 */ 169 244 static function apply_global($params) 170 245 { … … 174 249 } 175 250 251 /** 252 * Build 'type_map', 'all_type_map' and 'undefined_type_map'. 253 */ 176 254 private static function build_maps() 177 255 { … … 201 279 } 202 280 } 203 204 281 } 205 282
Note: See TracChangeset
for help on using the changeset viewer.