1

我的图像在调整大小后没有显示。

require('connect.php');

if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 

  // Temporary file name stored on the server
  $tmpName  = $_FILES['image']['tmp_name'];  
  $imagename = $_FILES["image"]["name"];

          // Get new dimensions
  list($width, $height) = getimagesize($tmpName);
  echo "orginal width".$width."<br/>";
  echo "orginal height".$height."<br/>";

  $new_width= $width * 0.5;
  $new_height = $height * 0.5;

  echo "new width".$new_width."<br/>";
  echo "new height".$new_height."<br/>"; //Its working fine till here.
  $image_p = imagecreatetruecolor($new_width, $new_height);
  $image = imagecreatefromjpeg($tmpName);
  imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  echo "My image"."<br>";
  echo '<img src="data:image/png|image/jpeg|image/gif;base64,' . base64_encode( $image_p ) . '" style="max-width:400px; max-height:300px;"/>'; 
  /* This line is not able to display the image. 
     Also tried imagejpeg($image_p, null, 100);. Not working , but anyway i need to
     display image alongwith other content so i have used echo. Not sure which 
     variable i should work with to display the image and how do i do it.*/
}
4

1 回答 1

0

在我看来,您缺少一步,将图像资源编码为 jpeg 图像(例如......)。

您可以将结果从类似文件输出imagejpeg到文件并提供文件,或者您可以使用输出缓冲捕获其输出并像现在一样提供它。

于 2012-08-19T14:03:57.200 回答