这是一个获取高分辨率图像的示例。
<?php
class resizeImage
{
public function resize_img($origimg,$newimg,$w,$h){
$info = getimagesize($origimg);
$mime = $info['mime'];
if(substr($mime, 0, 6) != 'image/')
{
header('HTTP/1.1 400 Bad Request');
return 'Error: requested file is not an accepted type: ' .$origimg;
exit();
}
$extension = image_type_to_extension($info[2]);
if(strtolower($extension) == '.png'){
$img = $this->resize_imagepng($origimg,$w, $h);
imagepng($img,$newimg);
imagedestroy($img);
}elseif(strtolower($extension) == '.jpeg'){
$img = $this->resize_imagejpeg($origimg, $w, $h);
imagejpeg($img, $newimg);
imagedestroy($img);
}elseif(strtolower($extension == '.gif')){
$img = $this->resize_imagegif($origimg, $w, $h);
imagegif($img,$newimg);
imagedestroy($img);
}
}
private function resize_imagepng($file, $w, $h) {
list($width, $height) = getimagesize($file);
$src = imagecreatefrompng($file);
$dst = imagecreatetruecolor($w, $h);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $w, $h, $width, $height);
return $dst;
}
private function resize_imagejpeg($file, $w, $h) {
list($width, $height) = getimagesize($file);
$src = imagecreatefromjpeg($file);
$dst = imagecreatetruecolor($w, $h);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $w, $h, $width, $height);
return $dst;
}
private function resize_imagegif($file, $w, $h) {
list($width, $height) = getimagesize($file);
$src = imagecreatefromgif($file);
$dst = imagecreatetruecolor($w, $h);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $w, $h, $width, $height);
return $dst;
}
}
?>