Is it possible to store 'Data URL' extracted from a canvas by toDataURL("image/png");
in a database and reconstruct the image by retrieving this 'Data URL'? I have tried to store the 'data URL' to a BLOB
.
I don't understand all you want to make, but here is a little example of the process I used.
First convert the canvas to an imageUrl with canvas.toDataURL() which returns a DataURL of the canvas in .png format.
Client:
var canvas=document.getElementById("canvas");
var dataURL=canvas.toDataURL();
$.ajax({
type: "POST",
url: "PHPfile.php",
data: {
image: dataURL
}
})
PHP:
<?php
$conn = new PDO('mysql:host=XXXX;dbname=YYY', "ZZZ", "1234");
$insert="insert into designs(image) values(:image)";
$stmt = $conn->prepare($insert);
$stmt->bindValue(":image",$_POST["image"]);
$stmt->execute();
Now you have the image stored on your DB.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.