Base64 clipping images from database PHP

末鹿安然 提交于 2019-12-25 01:17:20

问题


I am making a website that displays games from a database made in MySQL workbench. I want to have images appear next to the relevant game title of said game. The problem I am having is that I am inserting these images into my database using BLOB and converting them to base64 within the PHP. When I do this and run it, the images come out clipped.

This gets the information from the table that I created in MySQL

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

This is the table that pulls the information that I want from the database and converts the blob to a base64 image, but the images appear clipped.

'<?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>

'

The image should appear just fine but comes out with a white clip on the bottom that changes for each image even though they are all the same size in pixels.

Evidence that the images display, but are clipped


回答1:


For anyone who had the same issue as me: Courtesy of Jeff (https://stackoverflow.com/users/2417483/jeff), I was just being silly, and it turned out all I needed to do was make it a MEDIUMBLOB or LONGBLOB depending on the file sizes of your images.



来源:https://stackoverflow.com/questions/56310353/base64-clipping-images-from-database-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!