static function resizePicture($source_path, $dest_path, $new_width = 71, $new_height = 71, $img_y = 0, $img_x = 0, $img_width = 0, $img_height = 0, $max_size = 500)
{
//get img informations (dimensions and extension)
$img_infos = getimagesize($source_path);
if (empty($img_width)) {
$img_width = $img_infos[0];
}
if (empty($img_height)) {
$img_height = $img_infos[1];
}
if (empty($new_width)) {
$new_width = $img_infos[0];
}
if (empty($new_height)) {
$new_height = $img_infos[1];
}
// Image max size is 500 pixels : is set to 0 no resize
if ($max_size > 0) {
if ($img_width > $max_size || $img_height > $max_size) {
$source_aspect_ratio = $img_width / $img_height;
if ($source_aspect_ratio < 1) {
$new_width = $max_size * $source_aspect_ratio;
$new_height = $max_size;
} else {
$new_width = $max_size;
$new_height = $max_size / $source_aspect_ratio;
}
}
}
$img_type = $img_infos[2];
switch ($img_type) {
case IMAGETYPE_BMP:
$source_res = imagecreatefromwbmp($source_path);
break;
case IMAGETYPE_GIF:
$source_res = imagecreatefromgif($source_path);
break;
case IMAGETYPE_JPEG:
$source_res = imagecreatefromjpeg($source_path);
break;
case IMAGETYPE_PNG:
$source_res = imagecreatefrompng($source_path);
break;
default:
return false;
}
//create new img resource for store thumbnail
$source_dest = imagecreatetruecolor($new_width, $new_height);
//resize image
imagecopyresampled($source_dest, $source_res, 0, 0, $img_x, $img_y, $new_width, $new_height, $img_width, $img_height);
//output img
return imagejpeg($source_dest, $dest_path, 90);
}