00001 <?php
00002 Load::components('imagetoolsrect');
00003
00004
00005
00006
00007
00008
00009 class ImageToolsCalculator {
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 public static function fit($src_width, $src_height, $dst_width, $dst_height) {
00023 if (($src_width / $src_height) == ($dst_width / $dst_height)) {
00024 return new ImageToolsRect($dst_width, $dst_height);
00025 }
00026
00027 $w_target = min($src_width, $dst_width);
00028 $h_target = min($src_height, $dst_height);
00029
00030 $x_ratio = $w_target / $src_width;
00031 $y_ratio = $h_target / $src_height;
00032 $ratio = min($x_ratio, $y_ratio);
00033
00034 $w_target = ceil($src_width * $ratio);
00035 $h_target = ceil($src_height * $ratio);
00036
00037 return new ImageToolsRect($w_target, $h_target);
00038 }
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 public static function center($src_width, $src_height, $dst_width, $dst_height) {
00051 $x_target = ($dst_width - $src_width) / 2;
00052 $y_target = ($dst_height - $src_height) / 2;
00053
00054 return new ImageToolsRect($src_width, $src_height, $x_target, $y_target);
00055 }
00056 }