How to Generate Image from html using js?

How to Generate Image from html using js?

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.

26 responses

26 thoughts on “How to Generate Image from html using js?”

  1. Escort Bayan

    This is really attention-grabbing, You are an excessively professional blogger. Kira Sheff Chancey

  2. Saymarilyn

    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

  3. kavin

    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.

  4. Derma Prime

    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.

  5. Marijuana Gummies

    Really appreciate you sharing this article.Really looking forward to read more. Fantastic.

  6. Tara

    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!

  7. Santo Winter

    terrific as well as fantastic blog. I really intend to thank
    you, for providing us far better details.

  8. Shanon Lavarack

    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.

  9. Cesared Mundlatouche

    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. . . . . .

  10. Goddess Fiona

    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.

  11. XMC-plLow

    I’m curious which websites and online portals people visit most frequently. Do you mostly use news websites, social media, forums, entertainment portals, or specialized websites related to your hobbies and interests?

    Personally, I tend to visit a few websites regularly rather than constantly switching between different portals. I’m interested to hear what other people use on a daily basis and which websites they simply couldn’t imagine being without.

    What are the websites you visit most often?

  12. Allanjiste

    MindSift Scales Marketing Intelligence Suite to Help Marketing Teams Recognize and Target In-Market Customers

    All-in-One environment unites audience data, customer verification, buyer signals and multichannel outreach together to help organizations make more informed growth decisions

    Manchester, NH — 2026 — MindSift, a audience insight and marketing software business, today highlighted the ongoing expansion of its unified solution built to enable advertisers, sales groups and business leaders more effectively pinpoint, understand and engage priority segments

    The MindSift technology connects consumer and business information, customer matching, online engagement insight, audience construction and shopping data within a shared advertising environment. By joining these functions, MindSift enables teams to shift from audience discovery to activation without depending on disconnected data tools and marketing platforms

    “Current advertising organizations have use of huge quantities of information, but translating that insight into usable action remains a serious hurdle,” said a MindSift representative. “MindSift is centered on making that workflow easier by allowing teams find the correct segments, identify relevant buying indicators and deploy their insights across the mediums they currently work with.”

    Converting Information Into Actionable Audience Value

    MindSift provides availability of a vast database of individual and business intelligence that businesses can apply to develop deeply targeted lists based on audience, business, behavior and intent-based signals

    The solution’s capabilities encompass audience construction, site visitor intelligence, record enhancement, purchase-intent analytics and audience engagement

    Rather than managing these tools as distinct advertising functions, MindSift unites them in a single view to provide companies a more complete picture of likely customers and their potential purchase intent

    Enabling Businesses Spot Customer Signals Sooner

    A key part of the MindSift solution is its capacity to assist organizations detect data points that may signal rising attention in a specific service, solution or area

    Companies can draw on these data points to rank audiences, enrich current customer and prospect profiles and boost the speed and precision of their marketing and outreach engagement

    MindSift’s Outreach Intelligence capability also expands this capability by feeding buying data and sales cues into current CRM and growth systems

    Made for Current Data-Driven Marketing

    MindSift is engineered for companies including marketing and sales teams to digital specialists, marketing agencies and company operators seeking to achieve greater value of proprietary and partner insight

    The system powers many main advertising workflows, including:

    Creating very specific individual and company lists
    Recognizing earlier unknown online guests
    Enriching current CRM and opportunity information
    Recognizing purchase-intent data
    Focusing on leads based on important data
    Deploying buyers across marketing and sales platforms
    Linking marketing analytics with present business software

    By unifying these tools, MindSift seeks to cut the effort required for converting big data collections into practical marketing outcomes

    About MindSift

    MindSift is a audience analytics and marketing technology provider supplying tools for segment development, identity verification, engagement intelligence, buyer signals, data augmentation and growth activation. Its solution is designed to empower advertisers, growth departments, digital specialists and businesses translate signals into usable buyer understanding

  13. XMC-plLow

    I’m curious which websites and online portals people visit most frequently. Do you mostly use news websites, social media, forums, entertainment portals, or specialized websites related to your hobbies and interests?

    Personally, I tend to visit a few websites regularly rather than constantly switching between different portals. I’m interested to hear what other people use on a daily basis and which websites they simply couldn’t imagine being without.

    What are the websites you visit most often?

  14. XrumerNip

    7 con configuración llave en mano en tu propio VPS.

    ¡Buena suerte, amigos!
    Base de datos de enlaces de Xrumer, base de datos de Xrumer, bases de datos Xrumer 23, proxies para reCAPTCHA, proxies IPv6 para reCAPTCHA

Leave a Reply

Your email address will not be published. Required fields are marked *