How to Generate Image from html using js?
This tutorial is about generating the image from the HTML. You can just create the HTML and put this code after your code, and it will generate the image from your HTML. Below is the easy step to generate the image from custom HTML.
Step 1)
Create one PHP file like index.php as below.
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Html To Image</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"> </script>
<script src="https://files.codepedia.info/files/uploads/iScripts/html2canvas.js"> </script>
<div class="bingo-box bingo-green generatedata" id="generatedata1" data-id="1">
<div class="number-row number-row1">
<div class="number number1">1</div>
<div class="number number2">2</div>
<div class="number number4">4</div>
<div class="number number5">5</div>
<div class="number number5">9</div>
</div>
</div>
<script>
$(document).ready(function() {
var getCanvas;
$( ".generatedata" ).each(function( index ) {
var dataid = $( this ).attr("id");
var catid = $( this ).data("id");
var datafid = parseInt(index) + parseInt(1);
var element = $("#"+dataid);
html2canvas(element, {
onrendered: function(canvas) {
getCanvas = canvas;
var imgageData = getCanvas.toDataURL("image/png");
var newData = imgageData.replace(/^data:image\/png/, "data:application/octet-stream");
$.ajax({
type: "POST",
url: "upload.php",
data: {
imgBase64: newData
}
}).done(function(o) {
console.log('saved');
});
}
});
});
});
</script>
Create another page like upload.php
<?php
$catid = $_POST['catid'];
$folderPath = "upload_img/";
$image_parts = explode(";base64,", $_POST['imgBase64']);
$image_type_aux = explode("image/", $image_parts[0]);
$image_type = $image_type_aux[1];
$image_base64 = base64_decode($image_parts[1]);
$filename = uniqid() . '.png';
$file = $folderPath . $filename;
file_put_contents($file, $image_base64);
?>
Step 3)
Now Just run the index.php file in your browser; this will generate the image in the folder.
I am incessantly thought about this, thanks for posting.
Really nice design and good subject material.
I could not refrain from commenting. Very well written! Anita Marten Britta
This is really attention-grabbing, You are an excessively professional blogger. Kira Sheff Chancey
I like the valuable info you provide in your articles. I will bookmark your weblog and check again here frequently. I am quite sure I will learn lots of new stuff right here! Best of luck for the next! Ediva Si Belden
Hi i am kavin, its my first occasion to commenting anyplace, when i read this paragraph i
thought i could also create comment due to this good
piece of writing.
Can I just say what a relief to discover a person that
genuinely knows what they are talking about
online. You actually understand how to bring a problem to light and make
it important. A lot more people must read this and understand this side of the story.
I can’t believe you aren’t more popular since you certainly have the gift.
Excellent write-up.
I absolutely appreciate this website.
Keep writing!
I think this is a real great blog article. Really Cool.
Really appreciate you sharing this article.Really looking forward to read more. Fantastic.
hi this is hi try content laa. I think that’s enough to try ulaaaaaaaaaaaaaaaa
Pretty great post. I just stumbled
upon your weblog and wished to say
that I’ve really enjoyed browsing your blog
posts. After all I’ll be subscribing to your feed and I hope
you write once more very soon!
terrific as well as fantastic blog. I really intend to thank
you, for providing us far better details.
I like what you guys are usually up too. This sort of clever work and exposure!
Keep up the very good works guys I’ve included you
guys to blogroll.
Hiya very nice site!! Guy .. Beautiful .. Amazing .. I will bookmark
your blog and take the feeds also? I am happy to find numerous useful information here within the publish, we need work out extra techniques in this regard, thanks for
sharing. . . . . .
I’m impressed, I have to admit. Rarely do I come across a
blog that’s both educative and entertaining, and let
me tell you, you’ve hit the nail on the head. The issue is
an issue that too few men and women are speaking intelligently about.
Now i’m very happy I stumbled across this in my search for something relating to this.
Really appreciate it!
This means a lot, thank you!
I’m truly grateful!
Original pet humor on premium U.S. cotton. Free shipping over $50. PAWS10 saves you 10%. snarkpaws.com
We make shirts for the kind of person who has had a three-hour conversation about their Golden. With strangers. While the dog was right there. snarkpaws.com
FixedFloat.com is a scam exchange—they stole my money! ff.io send cryptocurrency with HIGH AML! ff.io linked to gambling and drugs!
Three blanks at checkout — washed Comfort Colors, classic Bella+Canvas, heavyweight Gildan. $30 to $34. snarkpaws.com
Grand League selection in matches where teams have a clear record of winning on specific pitch types.