diff options
Diffstat (limited to 'i.php')
-rw-r--r-- | i.php | 41 |
1 files changed, 36 insertions, 5 deletions
@@ -283,12 +283,34 @@ function parse_request() function try_switch_source(DerivativeParams $params, $original_mtime) { global $page; + $original_size = null; + if (isset($page['original_size'])) + { + $original_size = $page['original_size']; + if ($page['rotation_angle']==90 || $page['rotation_angle']==270) + { + $tmp = $original_size[0]; + $original_size[0] = $original_size[1]; + $original_size[1] = $tmp; + } + } + + $use_watermark = $params->use_watermark; + if ($use_watermark) + { + if (!isset($original_size)) + return false; // cannot really know if a watermark is required + $dsize = $params->compute_final_size($original_size); + $use_watermark = $params->will_watermark($dsize); + ilog($use_watermark, $dsize); + } + $candidates = array(); foreach(ImageStdParams::get_defined_type_map() as $candidate) { if ($candidate->type == $params->type) continue; - if ($candidate->use_watermark != $params->use_watermark) + if ($candidate->use_watermark != $use_watermark) continue; if ($candidate->max_width() < $params->max_width() || $candidate->max_height() < $params->max_height()) continue; @@ -301,9 +323,9 @@ function try_switch_source(DerivativeParams $params, $original_mtime) { if ($candidate->sizing->max_crop!=0) continue; // this could be optimized - if (!isset($page['original_size'])) + if (!isset($original_size)) continue; - $candidate_size = $candidate->compute_final_size($page['original_size']); + $candidate_size = $candidate->compute_final_size($original_size); if ($candidate_size[0] < $params->sizing->min_size[0] || $candidate_size[1] < $params->sizing->min_size[1] ) continue; } @@ -324,7 +346,9 @@ function try_switch_source(DerivativeParams $params, $original_mtime) $page['src_path'] = $candidate_path; $page['src_url'] = $page['root_path'] . substr($candidate_path, strlen(PHPWG_ROOT_PATH)); $page['rotation_angle'] = 0; + return true; } + return false; } function send_derivative($expires) @@ -476,7 +500,6 @@ SELECT * { $page['rotation_angle'] = pwg_image::get_rotation_angle_from_code($row['rotation']); } - } if (!$row) { @@ -494,7 +517,15 @@ else } mysql_close($pwg_db_link); -try_switch_source($params, $src_mtime); +if (!try_switch_source($params, $src_mtime) && $params->type==IMG_CUSTOM) +{ + $sharpen = 0; + foreach (ImageStdParams::get_defined_type_map() as $std_params) + { + $sharpen += $std_params->sharpen; + } + $params->sharpen = round($sharpen / count(ImageStdParams::get_defined_type_map()) ); +} if (!mkgetdir(dirname($page['derivative_path']))) { |