简体   繁体   English

如何上传PNG,向其添加透明像素并将其写入数据库?

[英]How to upload a PNG, add transparent pixels to it, and write it to a database?

I am looking for information on how to retrieve a PNG file sent to the server via POST. 我正在寻找有关如何检索通过POST发送到服务器的PNG文件的信息。 Subsequently, I want to increase the height of the image to make it equal to the width by adding equal areas of transparent pixels to the top and bottom. 随后,我想通过在顶部和底部添加相等的透明像素区域来增加图像的高度,使其等于宽度。 Finally, I want to write this PNG to my database. 最后,我想将此PNG写入数据库。

Does anybody have any resources that could help? 有人有什么资源可以帮助您吗?

The below code will give you the way to upload the png image and check if it's a png one. 以下代码将为您提供上传png图像并检查其是否为png图像的方法。 Now to change the height and width of the image you should use the GD library or ImageMagick. 现在,要更改图像的高度和宽度,您应该使用GD库或ImageMagick。

Check here: PHP crop image to fix width and height without losing dimension ratio 在这里检查: PHP裁剪图像以固定宽度和高度而不会丢失尺寸比例

In order to INSERT into in the DB as a BLOB check here: 为了以BLOB形式插入DB中,请在此处进行检查:

Write image file to database as BLOB (PHP) 将图像文件作为BLOB(PHP)写入数据库

<?php // upload.php

echo <<<_END
<html><head><title>PHP Form Upload</title></head><body>
<form method='post' action='upload.php' enctype='multipart/form-data'> 
Select File: <input type='file' name='filename' size='10' />
<input type='submit' value='Upload' />
</form>
_END;

if ($_FILES)
{
   $name = $_FILES['filename']['name']; 
   $type = $_FILES['filename']['type']; 
   $size = $_FILES['filename']['size']; 
   if ($type == "image/png") {
   move_uploaded_file($_FILES['filename']['tmp_name'], $name); 

   /* once the image has been uploaded change the height and width using the 
   correct library and insert into the DB as a BLOB */

}else{
   die("You must upload a png file");
}
echo "</body></html>"; ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM