调整图像和图像格式的大小

时间:2016-08-26 13:34:37

标签: php html mysql image format

下面是我用来在mysql数据库中检索3个blob类型图像的php代码!

虽然我成功地检索了它们,但我不明白如何嵌入html代码以控制检索到的图像的高度和宽度!

此外,我还可以检索png类型的图像。

请根据我上传到数据库的图像格式帮助我检索任何fomat(例如jpeg)中的图像(我已经获得了上传图像的类型。(例如 - $images1=getimagesize($_FILES['Image1']['tmp_name']); $imagetype1=$images1['mime'];))。

所以我需要2个主要帮助:

  1. 调整从上面的PHP代码中检索到的图像的宽度和高度

  2. 以格式

    检索图像
    <?php
            require("includes/db.php");
    
            $sql="SELECT * FROM `order` ";
            $result=mysqli_query($db,$sql);
    
    echo "<table>";
    
    
    while($row=mysqli_fetch_array($result))
    {
    
    echo"<tr>";
     echo"<td>";
    echo $row["OrderNo."];
     echo "<br>";
     echo"</td>";
     echo"<td>";
    echo $row["NIC"];
     echo "<br>";
     echo"</td>";
     echo"<td>";
    echo $row["DP"];
     echo "<br>";
     echo"</td>";
     echo"<td>";
    echo $row["Address"];
     echo "<br>";
     echo"</td>";
     echo"<td>";
    echo $row["DPTime"];
     echo "<br>";
     echo"</td>";
     echo"<td>";
    echo $row["Telephone"];
     echo "<br>";
     echo"</td>";
     echo"<td>";
    echo $row["Email"];
     echo "<br>";
     echo"</td>";
    echo"<td >";
    echo '<img src="data:image/png;base64,'.base64_encode( $row['Image1'] ).' " />';
    
    echo "<br>";
     echo"</td>";
    echo"<td >";
    echo '<img src="data:image/png;base64,'.base64_encode( $row['Image2'] ).' "/>';
    
    echo "<br>";
     echo"</td>";
      echo"<td >";
     echo '<img src="data:image/png;base64,'.base64_encode( $row['Image3'] ).' "/>';
    
    echo "<br>";
     echo"</td>";
    
     echo"</tr>";
    
    }
    echo "</table>";
    
    ?>
    

1 个答案:

答案 0 :(得分:0)

  <?php

// This is the temporary file created by PHP
$uploadedfile ="search.png";

// Create an Image from it so we can do the resize
 $info = getimagesize($uploadedfile);
if ($info['mime'] == 'image/jpeg') 
        $src = imagecreatefromjpeg($uploadedfile);

    elseif ($info['mime'] == 'image/gif') 
        $src = imagecreatefromgif($uploadedfile);

    elseif ($info['mime'] == 'image/png') 
        $src = imagecreatefrompng($uploadedfile);
//$src = imagecreatefromjpeg($uploadedfile);


list($width,$height)=getimagesize($uploadedfile);

$newwidth=80;
$newheight=($height/$width)*80;
$tmp=imagecreatetruecolor($newwidth,$newheight);


imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);


$filename =$uploadedfile;
imagejpeg($tmp,$filename,100);

imagedestroy($src);
imagedestroy($tmp);











?>  

这样可以调整图像大小。