2013-08-16 64 views
0
//Get current dimensions 
$width = imagesx($myimage); 
$height = imagesy($myimage); 

$width = $width * ($zoom/100); 
$height = $height * ($zoom/100); 

$scale = min($new_width/$width, $new_height/$height); 

$new_width = ceil($scale * $width); 
$new_height = ceil($scale * $height); 




    imagecopyresampled($image_p, $myimage, 0, 0, $offset_x * -1, $offset_y * -1, $new_width, $new_height, $width, $height); 

我想放大的圖片,但實際上它變得更小,而不是放大的。變焦就像100分之113= 1.13的係數應該在13%縮放放大的照片嗎?

+0

你爲什麼要計算規模有多大?通過相同的比例縮放兩個尺寸應保持縱橫。 –

回答

1

我想你想要的是:

//Get current dimensions 
$width = imagesx($myimage); 
$height = imagesy($myimage); 

$new_width = $width * $zoom/100; //120 zoom will increase the image by 20% 
$new_height = $height * $zoom/100; 

imagecopyresampled($image_p, $myimage, 0, 0, 0, 0, $new_width, $new_height, $width, $height); 

實際上是在php.net的第一個例子是變焦例如: http://php.net/manual/en/function.imagecopyresampled.php