Skip to content

Commit

Permalink
feat: added tiff files preview support (#1222)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeidiDeng committed Mar 2, 2021
1 parent d8f415f commit e8c9d1c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
11 changes: 9 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 19 additions & 1 deletion frontend/src/components/files/ExtendedImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e8c9d1c

Please sign in to comment.