php - 在 php 中调整大小后显示图像出错

标签 php mysql image resize blob

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

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.*/
}

最佳答案

在我看来你错过了一步,将图像资源编码为 jpeg 图像(例如......)。

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

关于php - 在 php 中调整大小后显示图像出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12026988/

相关文章:

html - 未检测到 CSS 中的高度

javascript - 如何在WordPress中实现自定义逻辑?

php - 正则表达式 - 从字符串末尾开始搜索

php - 使用 PHP 或 Imagick 获取图像 ICC 配置文件

html - 用背景图像填充 SVG 路径元素

mysql - 如何获取一个月内剩余可预订天数?

php - MAMP:未定义的方法 mysqli_stmt::get_result()

php - 如何从 Cross Slide 图像库的数据库中获取图像?

mysql - Laravel 从用户表单输入详细信息获取数据库结果

mysql - 连接mysql中的4个表