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


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

我正在寻找有关如何检索通过POST发送到服务器的PNG文件的信息。随后,我想通过在顶部和底部添加相同面积的透明像素来增加图像的高度,使其等于宽度。最后,我想把这个PNG写入我的数据库。

谁有什么资源可以帮上忙?

下面的代码将为您提供上传png图像的方法,并检查它是否是png图像。现在要更改图像的高度和宽度,您应该使用GD库或ImageMagick。

检查这里:PHP裁剪图像固定宽度和高度而不丢失尺寸比

为了在数据库中插入一个BLOB,检查这里:

以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>"; ?>