来自数据库PHP的Base64剪切图像 [英] Base64 clipping images from database PHP

查看:86
本文介绍了来自数据库PHP的Base64剪切图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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;
}

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

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.

图像显示但被裁剪的证据

推荐答案

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

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.

这篇关于来自数据库PHP的Base64剪切图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆