2017-02-28 43 views
1

我想访问我上传的图像上传与1200 * 2000尺寸。但在访问时间我想访问它在200 * 150(其用户给定的值)在PHP维代码访问图像与给定的尺寸,由用户给出

+3

你有什么尝试到现在..请让我们知道吗? –

+0

我已经上传了一个尺寸的图像,但我想访问用户给定的欲望大小。 – aakash

+0

http://php.net/manual/en/function.imagecopyresized.php它会帮助你 –

回答

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); 
+0

...........但不适用于多个图像只适用于单个图像我想要根据我的尺寸的图像列表 – aakash

+0

请检查此代码,我已更改为2尺寸的拇指和小。 –

+0

如果你认为我的答案是有用的请投我我 –