2016-07-08 63 views
0

我想調整圖像的大小正好爲256 x 256像素。PHP圖像調整大小到正好是256 x 256像素拉伸

我目前使用...

$image_p = imagecreatetruecolor($imgMaxWidth, $imgMaxHeight); 
imagecopyresampled($image_p, $source, 0, 0, 0, 0, $imgMaxWidth, $imgMaxHeight, $imgWidth, $imgHeight); 

它只接受Maximum WidthMaximum Height

如果我上傳615 x 339像素的圖像,我將得到一個調整大小爲256 x 141像素的圖像。

你能幫我嗎?

回答

0

我不知道你在做什麼,但你的代碼應該工作

我已經試過這和它的作品:

<?php 
// The file 
$filename = 'test.jpg'; 
$source = imagecreatefromjpeg($filename); 

// Set your height and width 
$imgMaxWidth = 256; 
$imgMaxHeight = 256; 

// Content type 
header('Content-Type: image/jpeg'); 

// Get new dimensions 
list($imgWidth, $imgHeight) = getimagesize($filename); 

// This is the code you post 
$image = imagecreatetruecolor($imgMaxWidth, $imgMaxHeight); 
imagecopyresampled($image, $source, 0, 0, 0, 0, $imgMaxWidth, $imgMaxHeight, $imgWidth, $imgHeight); 

// Output 
imagejpeg($image, null, 100); 
?> 
+0

我做了同樣的方式顯示'的圖片:「http: //localhost/imageupload/untitled.php「無法顯示,因爲它包含錯誤.'這個錯誤................我也改變目標文件夾像這樣'imagepng($ image ,'photo_gallery /,100);' –

+0

第二個參數是文件名(字符串),所以: 'imagepng($ image,「photo_gallery/my_image.png」,100);' – dimasdmm

+0

它創建'my_image.png'文件'photo_gallery /'文件夾位它不是一個圖像文件,我無法打開,它的實際大小是0字節 –