static function thumbnail($pic, $dst_pic, $max_width, $max_height = null, $qulitity = 100, $copy = true)
{
$im = self::readfile($pic);
if ($im === false) {
return false;
}
$old_w = imagesx($im);
$old_h = imagesy($im);
if ($max_height == null) {
$max_height = $max_width;
}
if ($old_w > $max_width or $old_h > $max_height) {
$w_h = $old_w / $old_h;
$h_w = $old_h / $old_w;
if ($w_h > $h_w) {
$width = $max_width;
$height = $width * $h_w;
} else {
$height = $max_height;
$width = $height * $w_h;
}
$newim = imagecreatetruecolor($width, $height);
imagecopyresampled($newim, $im, 0, 0, 0, 0, $width, $height, $old_w, $old_h);
imagejpeg($newim, $dst_pic, $qulitity);
imagedestroy($im);
return true;
} elseif ($pic != $dst_pic and $copy) {
return copy($pic, $dst_pic);
} else {
return false;
}
}