来自数据库PHP的Base64剪切图像

时间:2019-05-26 03:12:01

标签: php html mysql base64 clipping

我正在建立一个网站,该网站显示MySQL工作台中建立的数据库中的游戏。我想让图像出现在所述游戏的相关游戏标题旁边。我遇到的问题是,我正在使用BLOB将这些图像插入数据库中,并将其转换为PHP中的base64。当我执行并运行它时,图像会被剪切掉。

这将从我在MySQL中创建的表中获取信息

function find_all_games(){
    global $db; //Connects to database
    $sql = 'SELECT * FROM game';
    $result = mysqli_query($db, $sql);
    return $result;
}

此表从数据库中提取我想要的信息,并将blob转换为base64图像,但这些图像似乎已被剪切。

'<?php while($game = mysqli_fetch_assoc($get_all_games)) {?>
<table>
    <tr>
      <td><?php
                echo '<img src="data:image/jpeg;base64,'.base64_encode($game['image']).' "height="301" width="220" />'; ?>
      </td>
    </tr>
    <tr>
      <td id="title"><?php echo $game['title']; ?></td>
    </tr>
    <tr>
      <td class="title">Released:</td>
      <td class="data"><?php echo $game['release_date']; ?></td>
    </tr>
    <tr>
      <td class="title">Publisher:</td>
      <td class="data"><?php echo $game['publisher']; ?></td>
    </tr>
</table>

'

图像看起来应该很好,但底部会出现一个白色的剪辑,即使每个像素的像素大小相同,该剪辑也会针对每个图像而变化。

Evidence that the images display, but are clipped

1 个答案:

答案 0 :(得分:0)

对于任何与我有相同问题的人: 感谢Jeff(https://stackoverflow.com/users/2417483/jeff)的帮助,我只是傻了,结果我要做的就是根据图像的文件大小将其设置为MEDIUMBLOB或LONGBLOB。