Edit this page

exportImage

Exports a group of drawing elements as an image.

The group will be positioned at [0, 0] in the exported image. It's dimensions will be used as default dimensions for the image.

The export operation is asynchronous and returns a promise.

The promise will be resolved with a PNG image encoded as a Data URI.

Important Scene images must be of same origin or CORS-enabled.

Parameters

group kendo.drawing.GroupThe root group containing all elements to export.
options ObjectParameters for the exported image.
options.width NumberThe width of the exported image. Defaults to the scene width.
options.height NumberThe height of the exported image. Defaults to the scene height.
options.cors String (default: "anonymous")Specifies how cross-origin images

should be requested.

Requesting images without CORS will "taint" the canvas. It will still be visible on the page, but all script access to it is disabled to prevent information disclosure.

By default they're requested anonymously. Available options are:

  • "anonymous" - do not send user credentials as part of the request
  • "use-credentials" - send credentials as part of the request
  • false - fetch images without CORS, possibly tainting the canvas

See crossorigin attribute for more details.

ReturnsPromise A promise that will be resolved with a PNG image encoded as a Data URI.

Example - Exporting a drawing to an image

<script>
    var draw = kendo.drawing;
    var geom = kendo.geometry;

    var rect = new geom.Rect([5, 5], [240, 240]);
    var path = draw.Path.fromRect(rect).stroke("red", 5);

    var root = new draw.Group();
    root.append(path);

    draw.exportImage(root, { width: "250px", height: "250px" }).done(function(data) {
        kendo.saveAs({
            dataURI: data,
            fileName: "frame.png"
        });
    });
</script>

Example - Position the scene within a larger image

<div class="content" style="background: #ffffff;">
    <p>Lorem ípsum dolor sit amét, pro éu facilis vulputáte témporibus. Eu méi modus requé. Unum gloriátur has et. Modo stet vix ei, apéirian iñsolens plátoñem has ex. Cum eí oporteat inímicus, prí soluta torquatos témporibus éu.</p>
    <p>Ut eos assúm mazim vócent, cu gloríatur expetéñdis pro. Héñdrerit ádversarium reprehendunt eos ad, dúo an noster feugiat cotidieque. Vocent erroribus repudiáre ad meí. Oratio soluta eripuit sed éx. Vis et meliore appellañtur, át has discere convenire ocurreret. Eos at mazim melius aliquip, aperiam alterum commuñé pro id, zril soluta efficiantur in sit. Duis mundi duo ex, pér offendit probatus suavítate iñ.</p>
    <p>Nec id fácilis similique, audiam moderatius ad eum. Persecuti liberavisse eum ex. Qui anímal audiré et, éum vitae coñsul dolorum eu, ín sed partem antíopam. Velít suscipit te usu. Mea ea melius scripta.</p>
    <p>Illum delenit neglegentúr te cum, in errór inimicus disseñtias mel, placérat ocurreret ea vix. Vix ea latine voluptatum. Cúm eu albucius democritum coñsetetur, vix eu dicat deleniti, omñes ínimicus nám no. Nihil molestiae vel ex.</p>
    <p>Eú ñominavi placerat his, eu vix timeam qualisque. Príma recusabo torquatós eos ad, ín meí próbo aequé. Ex ñoñumy vóluptua accommodare seá, sit át sanctus detráxit, ín eos case probatus tractatos. Id sit nihíl coñtentíones, ñec ut audiré elaboraret, quo alia ferri múñere ét.</p>
</div>
<script>
    var draw = kendo.drawing;
    var geom = kendo.geometry;

    var contentSize = new geom.Rect([0, 0], [800, 600]);
    var imageSize = new geom.Rect([0, 0], [1200, 800]);

    draw.drawDOM($(".content")).then(function (group) {
        // Fill the background and set the dimensions for the exported image
        var background = draw.Path.fromRect(imageSize, {
            fill: {
                color: "#ffffff",
            },
            stroke: null
        });

        // Fit content to size, if needed
        draw.fit(group, contentSize);

        // Note that the following methods accept arrays
        draw.align([group], imageSize, "center");
        draw.vAlign([group], imageSize, "center");

        // Bundle it all together
        var wrap = new draw.Group();
        wrap.append(background, group);

        // export the image and crop it for our desired size
        return draw.exportImage(wrap, {
            cors: "anonymous"
        });
    })
    .done(function(data) {
        kendo.saveAs({
            dataURI: data,
            fileName: "frame.png"
        });
    });
</script>
Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article

close
Dummy