header('content-type:text/html;charset=utf-8');
//定义要操作图片的文件
$filename = '../Public/Image/11.jpg';
//得到图片的信息
$fileinfo = getimagesize($filename);//返回值是数组
//print_r($fileinfo);
//exit();
//检测是否为真
if ($fileinfo){
//得到原始图像的宽高
$src_w=$fileinfo[0];
$src_h=$fileinfo[1];
$mime = $fileinfo['mime'];//得到图片类型
}else{
die('文件不是真实图片');
}
//根据图片类型得到创建画布资源的函数
$filetype = str_replace('/','createfrom',$mime);
//根据图片类型得到保存输出图像的函数
$outspace = str_replace('/',null,$mime);
//根据图片类型得到保存图像的后缀名
$latename = str_replace('image/',null,$mime);
//echo $latename;
//exit();
//动态创建原画布资源
$src_image = $filetype($filename);
//设置最大的宽高1000,695
$dst_w = 450;
$dst_h = 300;
$ratio_orig = $src_w/$src_h;
if ($dst_w/$dst_h > $ratio_orig) {
$dst_w = $dst_h*$ratio_orig;
} else {
$dst_h = $dst_w/$ratio_orig;
}
$dst_image = imagecreatetruecolor($dst_w,$dst_h);
//缩略图
imagecopyresampled($dst_image,$src_image,
0,0,0,0,
$dst_w,$dst_h,$src_w,$src_h);
$outspace($dst_image,'../Public/Image/bl.'.$latename);
imagedestroy($dst_image);
imagedestroy($src_image);
php gd image