feat: added tiff files preview support (#1222)

This commit is contained in:
WeidiDeng 2021-03-02 19:14:32 +08:00 committed by GitHub
parent d8f415f8ab
commit e8c9d1c539
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 3 deletions

View File

@ -9929,8 +9929,7 @@
"pako": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.8.tgz",
"integrity": "sha512-6i0HVbUfcKaTv+EG8ZTr75az7GFXcLYk9UyLEg7Notv/Ma+z/UG3TCoz6GiNeOrn1E/e63I0X/Hpw18jHOTUnA==",
"dev": true
"integrity": "sha512-6i0HVbUfcKaTv+EG8ZTr75az7GFXcLYk9UyLEg7Notv/Ma+z/UG3TCoz6GiNeOrn1E/e63I0X/Hpw18jHOTUnA=="
},
"parallel-transform": {
"version": "1.1.0",
@ -12895,6 +12894,14 @@
"integrity": "sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==",
"dev": true
},
"utif": {
"version": "3.1.0",
"resolved": "http://mirrors.cloud.tencent.com/npm/utif/-/utif-3.1.0.tgz",
"integrity": "sha512-WEo4D/xOvFW53K5f5QTaTbbiORcm2/pCL9P6qmJnup+17eYfKaEhDeX9PeQkuyEoIxlbGklDuGl8xwuXYMrrXQ==",
"requires": {
"pako": "^1.0.5"
}
},
"util": {
"version": "0.11.1",
"resolved": "https://registry.npmjs.org/util/-/util-0.11.1.tgz",

View File

@ -19,6 +19,7 @@
"normalize.css": "^8.0.1",
"noty": "^3.2.0-beta",
"qrcode.vue": "^1.7.0",
"utif": "^3.1.0",
"vue": "^2.6.10",
"vue-i18n": "^8.15.3",
"vue-lazyload": "^1.3.3",

View File

@ -10,11 +10,12 @@
@mouseup="mouseUp"
@wheel="wheelMove"
>
<img :src="src" class="image-ex-img image-ex-img-center" ref="imgex" @load="onLoad">
<img src="" class="image-ex-img image-ex-img-center" ref="imgex" @load="onLoad">
</div>
</template>
<script>
import throttle from 'lodash.throttle'
import UTIF from 'utif'
export default {
props: {
@ -61,6 +62,9 @@ export default {
}
},
mounted() {
if (!this.decodeUTIF()) {
this.$refs.imgex.src = this.src
}
let container = this.$refs.container
this.classList.forEach(className => container.classList.add(className))
// set width and height if they are zero
@ -85,6 +89,20 @@ export default {
}
},
methods: {
// Modified from UTIF.replaceIMG
decodeUTIF() {
const sufs = ["tif", "tiff", "dng", "cr2", "nef"]
let suff = document.location.pathname.split(".").pop().toLowerCase()
if (sufs.indexOf(suff) == -1) return false
let xhr = new XMLHttpRequest()
UTIF._xhrs.push(xhr)
UTIF._imgs.push(this.$refs.imgex)
xhr.open("GET", this.src)
xhr.responseType = "arraybuffer"
xhr.onload = UTIF._imgLoaded
xhr.send()
return true
},
onLoad() {
let img = this.$refs.imgex