Skip to content

Commit c3aca7f

Browse files
authored
Merge pull request #16 from nextcloud/svg-support
Add svg support
2 parents e8cc15c + a3fef82 commit c3aca7f

4 files changed

Lines changed: 37 additions & 3 deletions

File tree

viewer/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

viewer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"nextcloud-server": "^0.15.9",
4040
"nextcloud-vue": "^0.8.0",
4141
"vue": "^2.6.7",
42+
"vue-async-computed": "^3.6.1",
4243
"xml2js": "^0.4.19"
4344
},
4445
"browserslist": [

viewer/src/components/Images.vue

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
<template>
2424
<img
25-
:src="path"
25+
:src="data"
2626
:style="{
2727
height: height + 'px',
2828
width: width + 'px'
@@ -32,19 +32,46 @@
3232

3333
<script>
3434
import mime from 'Mixins/Mime'
35+
import axios from 'axios'
36+
import Vue from 'vue'
37+
import AsyncComputed from 'vue-async-computed'
38+
39+
Vue.use(AsyncComputed)
3540
3641
export default {
3742
name: 'Videos',
3843
mixins: [
3944
mime
4045
],
46+
asyncComputed: {
47+
data() {
48+
if (this.mime !== 'image/svg+xml') {
49+
return this.path
50+
}
51+
return this.getBase64FromImage()
52+
}
53+
},
4154
methods: {
4255
updateImgSize() {
4356
const naturalHeight = this.$el.naturalHeight
4457
const naturalWidth = this.$el.naturalWidth
45-
this.updateHeightWidth(naturalHeight, naturalWidth)
58+
// displaying tiny images makes no sense,
59+
// let's try to an least dispay them at 100x100
60+
this.updateHeightWidth(
61+
Math.max(naturalHeight, 100),
62+
Math.max(naturalWidth, 100)
63+
)
4664
4765
this.doneLoading()
66+
},
67+
/**
68+
* Manually retrieve the path and return its base64
69+
*
70+
* @returns {String}
71+
*/
72+
async getBase64FromImage() {
73+
const file = await axios.get(this.path)
74+
return `data:${this.mime};base64,${btoa(file.data)}`
4875
}
4976
}
5077
}

viewer/src/models/images.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export default {
3030
'image/jpeg',
3131
'image/gif',
3232
'image/x-xbitmap',
33-
'image/bmp'
33+
'image/bmp',
34+
'image/svg+xml'
3435
],
3536
component: Images
3637
}

0 commit comments

Comments
 (0)