Image dimension rendered by html2canvas

Asked

Viewed 182 times

0

I have a script that creates an image of a div using html2canvas and would like to know if there is any way to change the whidth and the height of that image.

<div id="MinhaDiv">Conteúdo a ser renderizado</div>
<input id="Gerador" type="button" value="Gerar Imagem"/>
<div id="IMGfinal" ></div>

<script>
    $(document).ready(function(){
        var element = $("#MinhaDiv"); 

        $("#Gerador").on('click', function () {
            html2canvas(element, {
            onrendered: function (canvas) {
            $("#IMGfinal").append(canvas);
                }
            });
        });
</script>

1 answer

1


To html2canvas documentation offers extra configuration options such as width and height, which can be declared in the function itself:

$(document).ready(function(){
    var element = $("#MinhaDiv"); 

    $("#Gerador").on('click', function () {
        html2canvas(element, { width: 500, height: 500,
        onrendered: function (canvas) {
        $("#IMGfinal").append(canvas);
            }
        });
    });
  • Thanks, it helped me a lot. I was using the properties the wrong way, but now everything works top;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.