js

[javaScript] .tif File 불러오기

natrue 2022. 2. 15. 16:06
728x90

tiff.min.js 추가 

http://seikichi.github.io/tiff.js/tiff.min.js

js

<script src="//code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://seikichi.github.io/tiff.js/tiff.min.js"></script>

<script type="text/javascript">
$(function () 
{
	var img_list = ["sample1.tif", "sample2.tif"];
	var load_img = function (filename) 
	{
		var xhr = new XMLHttpRequest();
		xhr.open("GET", filename);
		xhr.responseType = "arraybuffer";
		xhr.onload = function (e)
		{
			var buffer = xhr.response;
			var tiff = new Tiff({buffer: buffer});
			var canvas = tiff.toCanvas();
			var width = tiff.width();
			var height = tiff.height();
			if(canvas)
			{
				var $elem = $("<div><a href='" + filename + "'>" + filename + " (width: " + width + ", height:" + height + ")" + "</a></div>");
				$elem.append(canvas);
				$("body").append($elem);
			}
		};
		xhr.send();
	};

	for(var i = 0, len = img_list.length; i < len; ++i) 
	{
		load_img(img_list[i]);
	}
});
</script>

 

 

 

 

 

 

 

 

 

출처 : https://am0900.tistory.com/159