简体   繁体   English

使用扩展名将图像另存为jpg

[英]Save image as jpg with extension

I'm using Backbone and html2canvas.js, this is the code I have so far for transforming a div to canvas and saving it. 我正在使用Backbone和html2canvas.js,这是到目前为止我将div转换为画布并保存它的代码。 It works, but it doesn't add the .jpg extension. 它可以工作,但不添加.jpg扩展名。 Because of this, after downloading the image, FF and Chrome first ask me about the program I want to use to open the file and IE just tells me that I don't have the right program and suggests visiting the store. 因此,在下载图像后,FF和Chrome首先询问我要用来打开文件的程序,而IE只是告诉我我没有正确的程序,建议您去商店。

In FF and Chrome I can see the image when choosing the default Windows picture viewer etc. 在FF和Chrome中,选择默认的Windows图片查看器等时可以看到图像。

What I would like to achieve is to add the .jpg extension so the file opens in the default program right away: 我想要实现的是添加.jpg扩展名,以便该文件立即在默认程序中打开:

 savePicture: function() {
    //$(this.el).find('.drag-img').unwrap();
    var image = $(this.el).find('#droppable2');

    html2canvas(image, {
        onrendered: function(canvas) {
            var img = canvas.toDataURL("image/jpeg");


            var frame = document.getElementById("myHideFrame");
            if (!frame) {
                frame = document.createElement("iframe");
                frame.id = "myHideFrame";
                document.body.appendChild(frame);
            }
            frame.src = img.replace(/^data[:]image\/(png|jpg|jpeg)[;]/i, "data:application/octet-stream;");


        }
    });
},

Sadly, IE8 and above only supports data URIs in CSS, <link> , and <img> . 可悲的是, IE8及更高版本仅支持CSS, <link><img>数据URI So adding it to a frame as you are doing will not work. 因此,按原样将其添加到框架将不起作用。

Could you, for IE8 and above, put the data into an <img> and ask the user to right click and save the image? 对于IE8及更高版本,您能否将数据放入<img>并要求用户右键单击并保存图像?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM