我想访问我上传的1200 * 2000维度的上传图片。但是在访问时我想在PHP代码中以200 * 150(用户给定的值)维度访问它
答案 0 :(得分:1)
在这种情况下,您必须将上传的图像调整为重击(200 * 150)和小(400 * 300)。这是jpg和jpeg图像。
$filename = 'source.jpg';
// Get new sizes
list($width, $height) = getimagesize($filename);
$thumb_width = 200;
$thumb_height = 150;
$small_width = 400;
$small_height = 300;
// Load
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
$small = imagecreatetruecolor($small_width, $small_height);
$source = imagecreatefromjpeg($filename);
// Resize thumb
imagecopyresized($thumb, $source, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height);
// Resize small
imagecopyresized($small, $source, 0, 0, 0, 0, $small_width, $small_height, $width, $height);
// Output thumb
imagejpeg($thumb, "thumb.jpg");
// Output small
imagejpeg($small, "small.jpg");
//save memory
imagedestroy($thumb);
imagedestroy($small);