简体   繁体   English

如何使用fabric.js加载TIFF图像?

[英]How to load TIFF image with fabric.js?

From what I can tell, fabric.js can only load either JPG or PNG files. 据我所知,fabric.js只能加载JPG或PNG文件。 It fails when I try to load a TIFF file. 当我尝试加载TIFF文件时失败。 Any idea? 任何想法?

fabric.Image.fromURL('my_image.tif', function(oImg) {
  canvas.add(oImg);
});

This is not really a problem with FabricJS, but more that browsers in general does not support the TIFF file format . FabricJS并不是真正的问题,但更多的是,浏览器通常不支持TIFF文件格式 IE and Safari being exceptions as well as some less mainstream browsers. IE和Safari以及一些不太主流的浏览器都是例外。

Workarounds 解决方法

However, it is possible to read and parse TIFF files manually. 但是,可以手动读取和解析TIFF文件。 To read TIFF you can use for example tiff-js . 要阅读TIFF,可以使用例如tiff-js You may be able to get plugins for a browser that can decode TIFFs (the latter will possibly require end-user to also install the plugin as well). 您可能能够为可解码TIFF的浏览器获取插件(后者可能会要求最终用户也安装该插件)。

Though, I would recommend you to convert TIFF to for example PNG for general use. 不过,我建议您将TIFF转换为例如PNG以供一般使用。

Similarly, you will not be able to save out TIFF either for the same reasons as above, but feel free to look at my canvas-to-tiff solution for that (free). 同样,由于上述相同的原因,您也将无法保存 TIFF,但是请随意查看我的“ 画布到tiff”解决方案(免费)。

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

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