Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another way to create map image #62

Closed
leation opened this issue Jun 9, 2016 · 8 comments
Closed

Another way to create map image #62

leation opened this issue Jun 9, 2016 · 8 comments

Comments

@leation
Copy link

leation commented Jun 9, 2016

I have a idea to save map as image file by another way.First,convert html to canvas by html2canvas
javascript api,then save canvas to image by canvas2image javascript api.When I try this method in a
simple html page,everything is ok,but when I use this method in the “index.html” page which is under
“my-mind-master" folder,It can't work properly.After trying,I have found that if I remove "my-mind.js" in
my web page,every thing is ok,conversely,It can't work properly.
Sincerely hope that you can help me to solve this question.

@ondras
Copy link
Owner

ondras commented Jun 9, 2016

I have no experience with html2canvas. Try using this library via the JS console after the My Mind app is fully loaded to see whether it can make a screenshot or not.

@leation
Copy link
Author

leation commented Jun 9, 2016

My code as follows,the "onrendered" callback function can not jump in.There is no log output,maybe it because "my-mind.js" disabled related events?

function saveHtml2Image(divId, scale) {
            var obj = $("#" + divId);
            var width = obj.width();
            var height = obj.height();
            html2canvas(obj, {
                width: width,
                height: height,
                background: "rgba(255,255,255,1)",
                logging: true,
                onrendered: function (canvas) {
                    var dataUrl = Canvas2Image.saveAsJPEG(canvas, parseInt(width * scale), parseInt(height * scale));
                    var totalSize = dataUrl.length / 1024 / 1024;
                    if (totalSize > 1.3) {
                        dataUrl = null;
                        scale = scale - 0.1;
                        saveHtml2Image(divId, scale);
                    }
                    else {
                        $('#downloadImage').attr('href', dataUrl);
                        $('#downloadImage').attr('download', 'test.jpg');
                        $('#downloadImage')[0].click();
                    }
                }
            });
        }

@ondras
Copy link
Owner

ondras commented Jun 9, 2016

It would be great if you could publish your sample page (i.e. the My Mind installation with this script inside) somewhere. This snippet does not offer enough information. From where is this function called, with what argument values? Etc...

@leation
Copy link
Author

leation commented Jun 10, 2016

Code of the simple html page as follows:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>html2image</title>
    <script src="../js/jquery.min1.8.js"></script>
    <script src="../js/html2canvas.js"></script>
    <script src="../js/canvas2image.js"></script>
    <script>
        $(document).ready(function () {
            $("#saveAsImage").click(function (e) {
                saveHtml2Image("div1", 3);
            });
        });

        function saveHtml2Image(objId, scale) {
            document.body.scrollTop = 0;
            var obj = $("#" + objId);
            var width = obj.width();
            var height = obj.height();
            html2canvas(obj, {
                width: width,
                height: height,
                background: "rgba(255,255,255,1)",
                onrendered: function (canvas) {
                    var dataUrl = Canvas2Image.saveAsJPEG(canvas, parseInt(width * scale), parseInt(height * scale));
                    var totalSize = dataUrl.length / 1024 / 1024;
                    if (totalSize > 1.3) {
                        dataUrl = null;
                        scale = scale - 0.1;
                        saveHtml2Image(objId, scale);
                    }
                    else {
                        $('#downloadImage').attr('href', dataUrl);
                        //$('#downloadImage').attr('href', canvas.toDataURL());
                        $('#downloadImage').attr('download', 'test.jpg');
                        $('#downloadImage')[0].click();
                    }
                }
            });
        }
    </script>
</head>
<body>
    <div id="div1" style="color:red;padding:10px 10px;">
        <div>
            <span>
                hello,my english name is is leation.
            </span>
        </div>
        <div>
            <img style="width:500px;float:left;" src="../img/01.jpg" />
            <img style="width:500px;float:left;" src="../img/01.jpg" />
        </div>
        <div style="clear:both;"></div>
        <div>
            <span>
                hello,my english name is is leation.
            </span>
        </div>
        <div style="clear:both;"></div>
    </div>
    <div style="position:fixed;bottom:30px;right:30px;">
        <input type="button" value="saveHtmlAsImage" id="saveAsImage" />
        <a href="" id="downloadImage" style="display:none;">downloadImage</a>
    </div>
</body>
</html>

@leation
Copy link
Author

leation commented Jun 10, 2016

"html2canvas.js" and "canvas2image.js" .

@leation
Copy link
Author

leation commented Jun 10, 2016

I had solve this problem.The reason is the "Promise".I renamed the "Promise" to "PromisePlus" in whole content of "my-mind.js" file.

@52manhua
Copy link

52manhua commented Nov 1, 2016

It's a good ideal to use html2canvas.js,
By this way, I solved the CJK character screenshot problem.

@ondras ondras mentioned this issue Oct 16, 2021
16 tasks
@ondras
Copy link
Owner

ondras commented Oct 30, 2021

Exporting images should work once again! See #134 for more info.

@ondras ondras closed this as completed Oct 30, 2021
ondras added a commit that referenced this issue Oct 4, 2022
Sync GH pages with upstream repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants