如何在PHP中合并base64 png和预设png

时间:2016-10-21 11:20:48

标签: javascript php canvas

美好的一天。我正在将表单中的数据发送到php脚本以保存图像。它是通过XMLHttprequest发送的。基本图像通过$ _POST ['img']检索,并采用base 64格式。以下PHP脚本将其保存到服务器,它可以正常工作:

<?php

session_start();

$email = $_SESSION['email'];
$img = $_POST['img'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$fileData = base64_decode($img);
$fileName = "./gallery/" . bin2hex(openssl_random_pseudo_bytes(16)) . ".png";
file_put_contents($fileName, $fileData);

$conn = new PDO("mysql:host=localhost; dbname=camagru", "root", "admin");
$conn->setAttribute(PDO::ERRMODE_EXCEPTION);
$sql = $conn->prepare("INSERT INTO `images` (`image`, `email`) VALUES (:image, :email)");
$sql->bindParam(':image', $fileName);
$sql->bindParam(':email', $email);
$sql->execute();

?>

图片的帧(Overlay)被发送到$ _POST ['frame'],但它不是base64图像,它的文件名如下:'。/ frames / frame1.png'。如何合并这两个,并将其另存为$ fileName?

0 个答案:

没有答案