Changeset 13021 for trunk/include/derivative_params.inc.php
- Timestamp:
- Feb 2, 2012, 9:59:41 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/derivative_params.inc.php
r12908 r13021 34 34 } 35 35 36 function url_to_size($s)37 {38 $pos = strpos($s, 'x');39 if ($pos===false)40 {41 return array((int)$s, (int)$s);42 }43 return array((int)substr($s,0,$pos), (int)substr($s,$pos+1));44 }45 46 36 function size_equals($s1, $s2) 47 37 { … … 49 39 } 50 40 41 function char_to_fraction($c) 42 { 43 return (ord($c) - ord('a'))/25; 44 } 45 46 function fraction_to_char($f) 47 { 48 return ord('a') + round($f*25); 49 } 51 50 52 51 /** small utility to manipulate a 'rectangle'*/ … … 80 79 if (!empty($coi)) 81 80 { 82 $coil = floor($this->r * (ord($coi[0]) - ord('a'))/25);83 $coir = ceil($this->r * (ord($coi[2]) - ord('a'))/25);81 $coil = floor($this->r * char_to_fraction($coi[0])); 82 $coir = ceil($this->r * char_to_fraction($coi[2])); 84 83 $availableL = $coil > $this->l ? $coil - $this->l : 0; 85 84 $availableR = $coir < $this->r ? $this->r - $coir : 0; … … 116 115 if (!empty($coi)) 117 116 { 118 $coit = floor($this->b * (ord($coi[1]) - ord('a'))/25);119 $coib = ceil($this->b * (ord($coi[3]) - ord('a'))/25);117 $coit = floor($this->b * char_to_fraction($coi[1])); 118 $coib = ceil($this->b * char_to_fraction($coi[3])); 120 119 $availableT = $coit > $this->t ? $coit - $this->t : 0; 121 120 $availableB = $coib < $this->b ? $this->b - $coib : 0; … … 180 179 { 181 180 $tokens[] = size_to_url($this->ideal_size); 182 $tokens[] = sprintf('%02x', round(100*$this->max_crop));181 $tokens[] = fraction_to_char($this->max_crop); 183 182 $tokens[] = size_to_url($this->min_size); 184 183 } 185 184 } 186 187 static function from_url_tokens($tokens)188 {189 if (count($tokens)<1)190 throw new Exception('Empty array while parsing Sizing');191 $token = array_shift($tokens);192 if ($token[0]=='s')193 {194 return new SizingParams( url_to_size( substr($token,1) ) );195 }196 if ($token[0]=='e')197 {198 $s = url_to_size( substr($token,1) );199 return new SizingParams($s, 1, $s);200 }201 202 $ideal_size = url_to_size( $token );203 if (count($tokens)<2)204 throw new Exception('Sizing arr');205 206 $token = array_shift($tokens);207 $crop = hexdec($token) / 100;208 209 $token = array_shift($tokens);210 $min_size = url_to_size( $token );211 return new SizingParams($ideal_size, $crop, $min_size);212 }213 214 185 215 186 function compute($in_size, $coi, &$crop_rect, &$scale_size) … … 303 274 } 304 275 305 static function from_url_tokens($tokens)306 {307 $sizing = SizingParams::from_url_tokens($tokens);308 $ret = new DerivativeParams($sizing);309 return $ret;310 }311 312 276 function compute_final_size($in_size, $coi) 313 277 {
Note: See TracChangeset
for help on using the changeset viewer.