.

ImageToolsCalculator Class Reference
[ImageTools]

Offers some often used calculations for image resizing et al. More...

List of all members.

Static Public Member Functions

static  center ($src_width, $src_height, $dst_width, $dst_height)
  Center an image.
static  fit ($src_width, $src_height, $dst_width, $dst_height)
  Fit source into destination widthout changing ratio.

Detailed Description

Offers some often used calculations for image resizing et al.

Definition at line 9 of file imagetoolscalculator.cls.php.


Member Function Documentation

static ImageToolsCalculator::center ( src_width,
src_height,
dst_width,
dst_height  
) [static]

Center an image.

Parameters:
int  $src_width Source width
int  $src_height Source height
int  $dst_width Destination width
int  $dst_height Destiantion height
Returns:
ImageToolsRect

Definition at line 50 of file imagetoolscalculator.cls.php.

00050                                                                                         {
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         }
static ImageToolsCalculator::fit ( src_width,
src_height,
dst_width,
dst_height  
) [static]

Fit source into destination widthout changing ratio.

Example: Fit 200x100 into 100x100 will result in 100x50

Parameters:
int  $src_width Source width
int  $src_height Source height
int  $dst_width Destination width
int  $dst_height Destiantion height
Returns:
ImageToolsRect

Definition at line 22 of file imagetoolscalculator.cls.php.

00022                                                                                      {
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         }

The documentation for this class was generated from the following file: