简体   繁体   中英

How to load TIFF image with fabric.js?

From what I can tell, fabric.js can only load either JPG or PNG files. It fails when I try to load a TIFF file. 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 . IE and Safari being exceptions as well as some less mainstream browsers.

Workarounds

However, it is possible to read and parse TIFF files manually. To read TIFF you can use for example 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).

Though, I would recommend you to convert TIFF to for example PNG for general use.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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