简体   繁体   English

Firefox在“保存类型”-“另存为”对话框中错误的文件类型

[英]Firefox incorrect file type in Save as type - Save as dialog

I'm trying with FileSaver.js ( https://github.com/eligrey/FileSaver.js/ ) 我正在尝试使用FileSaver.js( https://github.com/eligrey/FileSaver.js/

When I save an image of type jpg, the save as dialog displaying in Firefox gives incorrect value at Save as type dropdown (It says "PNG Image ( .jpg), but what I expect is JPEG Image ( .jpg)). 当我保存jpg类型的图像时,在Firefox中显示的“另存为”对话框在“保存类型”下拉列表中给出了不正确的值(它显示为“ PNG图像( .jpg),但我期望的是JPEG图像( .jpg))。

Could anyone tell me how to fix this? 谁能告诉我该如何解决?

Finally, I found out the reason for this issue. 最后,我找出了这个问题的原因。

I use canvas-toblob javascript library to convert a canvas to blob. 我使用canvas-toblob javascript库将canvas转换为blob。 But Firefox has internal implementation for toblob method, so the same method in canvas-toblob.js is never called. 但是Firefox具有toblob方法的内部实现,因此从未调用canvas-toblob.js中的相同方法。

I modify canvas-toblob.js so that Firefox will use the method in this library. 我修改canvas-toblob.js,以便Firefox使用此库中的方法。 This solved my issue 这解决了我的问题

if (HTMLCanvasElement) { canvas_proto.toBlob = function(callback, type /*, ...args*/) { if (!type) { type = "image/png"; } if (this.msToBlob && /^\\s*image\\/png\\s*(?:$|;)/i.test(type)) { callback(this.msToBlob()); return; }

您需要为type参数指定image / jpeg。

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

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