HTML Div convert into image with background image Html2canvas

Martin

I am put canvas into one HTML div, After that i am converting this div into image using Html2canvas. HTML div successfully converted, but background image is not come.

I have seen one link but i am not sure. Because i have not seen any background image. Javascript html2canvas cant get background

please suggest me any idea.

$(function() { 
    $("#btnSave").click(function() { 
        html2canvas($("#html-to-canvas"), {
            onrendered: function(canvas) {
                theCanvas = canvas;
                document.body.appendChild(canvas);          
                Canvas2Image.saveAsPNG(canvas); 
                $("#canvas-image").append(canvas);              
            }
        });
    });
}); 
 .bg-img
   {
   		background-image:url('https://d2z4fd79oscvvx.cloudfront.net/0016463_petal_diamond_ring_320.jpeg');
   		background-repeat: no-repeat;
   		 
   }
<script src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
<script src="https://raw.github.com/niklasvh/html2canvas/gh-pages/build/html2canvas.js"></script>
  
<script src="https://raw.github.com/niklasvh/html2canvas/v0.34/src/plugins/jquery.plugin.html2canvas.js"></script>
  <div style="width:450px;height:500px;border:1px solid #333" class=" html-to-canvas bg-img"   id="html-to-canvas">   
            <canvas id="canvas" style="margin-left:100px;margin-top:150px" width="200" height="300"></canvas>
   </div>
<input type="button" id="btnSave" value="Save PNG"/>
<div id="canvas-image"></div>

Rayon

html2canvas or Canvas2Image does not work with external images.

All the images that the script uses need to reside under the same origin for it to be able to read them.Ref

Use relative path for the images and Try:

Working code:

$(function() {
  $("#btnSave").click(function() {
    html2canvas($("#html-to-canvas"), {
      onrendered: function(canvas) {
        Canvas2Image.saveAsPNG(canvas);
        $("#canvas-image").append(canvas);
      }
    });
  });
});
.bg-img {
  background-image: url('images/0016463_petal_diamond_ring_320.jpeg');
  background-repeat: no-repeat;
}
<div style="width: 450px; height: 500px; border: 1px solid #333" class=" html-to-canvas bg-img" id="html-to-canvas">
  <canvas id="canvas" style="margin-left: 100px; margin-top: 150px" width="200" height="300"></canvas>
</div>
<input type="button" id="btnSave" value="Save PNG" />
<div id="canvas-image"></div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

html2canvas capturing div image

From Dev

Saving canvas with background image to server with html2canvas

From Dev

convert html with highcharts graph to image using html2canvas

From Dev

HTML div background image not working

From Dev

html2canvas not capturing image

From Dev

html2canvas crop image on click

From Dev

html2canvas not taking capture of image

From Dev

html2canvas crop image on click

From Dev

HTML2Canvas - get created canvas image URI

From Dev

html div background image not showing up

From Dev

How to save html2canvas image into System Folder in jquery

From Dev

Codemirror & html2canvas: Save iFrame as Image

From Dev

html2canvas doesn't get image full height

From Dev

html2canvas generated image not picking svg in chart

From Dev

Saving Morris charts to image using HTML2CANVAS

From Dev

Scale image before toDataURL - html2canvas

From Dev

html2canvas not rendering image (externally hosted images)

From Dev

HTML2Canvas converting overflowed content to image

From Dev

Html2canvas - capture google map to image in phonegap application

From Dev

How to save html2canvas image into System Folder in jquery

From Dev

Saving Morris charts to image using HTML2CANVAS

From Dev

html2canvas doesn't render image at top left

From Dev

HTML/CSS: Image with Background Image

From Dev

Javascript - convert HTML div with SVG to image

From Dev

Html2Canvas then Canvas2Image cutting the generated image

From Dev

background image not showing in html

From Dev

Fixed position div in HTML sitting in front of background image of secondary div

From Dev

Move HTML5 Canvas with a background image

From Dev

Convert HTML string to image

Related Related

HotTag

Archive