return true;
}
- function img_thumb($src, $max_width, $max_height, $thumbs_dir = "", $background_color = array(255, 255, 255)){
+ function img_thumb($src, $max_width, $max_height, $thumbs_dir = "", $background_color = array(255, 255, 255), $CROP = false){
if(strlen($thumbs_dir) > 0){
if(!@is_dir($thumbs_dir)) @mkdir($thumbs_dir);
if(!@is_dir($thumbs_dir)) return false;
$thumbs_dir,
$thumb_file,
null,
- $background_color
+ $background_color,
+ $CROP
)
) === false
){
$thumbs_dir,
$thumb_file,
$quality = null,
- $background_color = array(255, 255, 255)
+ $background_color = array(255, 255, 255),
+ $CROP = false
){
$dest = $thumbs_dir.$thumb_file;
if(!($size = @getimagesize($src))) return false;
$thumb_img = imagecreatetruecolor($max_width, $max_height);
$thumb_bkg = imagecolorallocate($thumb_img, $background_color[0], $background_color[1], $background_color[2]);
imagefilledrectangle($thumb_img, 0, 0, $max_width, $max_height, $thumb_bkg);
+ if($CROP){
+ if($size[0] < $max_width || $size[1] < $max_height){
+ $CROP = false;
+ }
+ if($width == $max_width && $height == $max_height){
+ $CROP = false;
+ }
+ }
+ if($CROP){
+ $dst_x = 0;
+ $dst_y = 0;
+ $dst_w = $max_width;
+ $dst_h = $max_height;
+ if($width != $max_width){
+ $r = $max_width / $size[0];
+ $thumb_cut_height = (($size[1] * $r) - $max_height) / 2;
+ $img_cut_height = $size[1] * ($thumb_cut_height / $max_height);
+ $src_x = 0;
+ $src_y = floor($img_cut_height);
+ $src_w = $size[0];
+ $src_h = floor($size[1] - (2 * $img_cut_height));
+ }
+ else{
+ $r = $max_height / $size[1];
+ $thumb_cut_width = (($size[0] * $r) - $max_width) / 2;
+ $img_cut_width = $size[0] * ($thumb_cut_width / $max_width);
+ $src_x = floor($img_cut_width);
+ $src_y = 0;
+ $src_w = floor($size[0] - (2 * $img_cut_width));
+ $src_h = $size[1];
+ }
+ }
+ else{
+ $dst_x = floor(($max_width - $width) / 2);
+ $dst_y = floor(($max_height - $height) / 2);
+ $src_x = 0;
+ $src_y = 0;
+ $dst_w = $width;
+ $dst_h = $height;
+ $src_w = $size[0];
+ $src_h = $size[1];
+ }
imagecopyresampled(
$thumb_img,
$src_img,
- floor(($max_width - $width) / 2),
- floor(($max_height - $height) / 2),
- 0,
- 0,
- $width,
- $height,
- $size[0],
- $size[1]
+ $dst_x,
+ $dst_y,
+ $src_x,
+ $src_y,
+ $dst_w,
+ $dst_h,
+ $src_w,
+ $src_h
);
if(isset($quality)) $thumb_img = $thumb_function($thumb_img, $dest, $quality);
else $thumb_img = $thumb_function($thumb_img, $dest);