[英]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形式插入DB中,請在此處進行檢查:
<?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.