Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"axios": "^1.12.2",
"babel-loader": "^8.2.5",
"broadway-player": "^0.1.1",
"browser-image-compression": "^2.0.2",
"colorthief": "2.4.0",
"cytoscape": "^3.32.0",
"cytoscape-fcose": "^2.2.0",
Expand Down
46 changes: 42 additions & 4 deletions core/frontend/src/components/app/ImagePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@

<script lang="ts">
import axios from 'axios'
import imageCompression, { Options as ImageCompressionOptions } from 'browser-image-compression'
import Vue from 'vue'

import SpinningLogo from '@/components/common/SpinningLogo.vue'
Expand Down Expand Up @@ -143,6 +144,16 @@ export default Vue.extend({
default: null,
required: false,
},
maxDimension: {
type: Number,
default: 0,
required: false,
},
maxSizeMb: {
type: Number,
default: 0,
required: false,
},
},
data() {
return {
Expand Down Expand Up @@ -200,18 +211,18 @@ export default Vue.extend({
this.error = `Error deleting file: ${error}`
}
},
onFileInputChange(event: Event) {
async onFileInputChange(event: Event) {
const target = event.target as HTMLInputElement
const file = target.files?.[0]
if (!file) return
const fileName = encodeURIComponent(file.name)
this.uploadFile(file, `${this.directory}/${fileName}`)
await this.uploadImage(file, `${this.directory}/${fileName}`)
},
onFilePickerClick() {
const input = this.$refs.fileInput as HTMLInputElement
input.click()
},
async uploadFile(file: File, destination_path: string) {
async uploadFile(file: Blob, destination_path: string) {
const config = {
headers: {
'Content-Type': file.type,
Expand All @@ -224,11 +235,38 @@ export default Vue.extend({
})
this.loadImages()
},
async resizeImage(file: File): Promise<File> {
if (this.maxDimension <= 0 && this.maxSizeMb <= 0) {
return file
}

const options: ImageCompressionOptions = {
useWebWorker: true,
fileType: file.type,
}
if (this.maxDimension > 0) {
options.maxWidthOrHeight = this.maxDimension
}
if (this.maxSizeMb > 0) {
options.maxSizeMB = this.maxSizeMb
}
return imageCompression(file, options)
},
async uploadImage(file: File, destinationPath: string) {
try {
this.upload_error = null
const resizedImage = await this.resizeImage(file)
await this.uploadFile(resizedImage, destinationPath)
} catch (error) {
this.upload_error = `Error preparing image: ${error}`
console.error(this.upload_error)
}
},
async onDrop(event: DragEvent) {
const file = event.dataTransfer?.files?.[0]
if (!file) return
const fileName = encodeURIComponent(file.name)
await this.uploadFile(file, `${this.directory}/${fileName}`)
await this.uploadImage(file, `${this.directory}/${fileName}`)
},
},
})
Expand Down
4 changes: 4 additions & 0 deletions core/frontend/src/components/app/VehicleBanner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<image-picker
size="35px"
directory="/userdata/images/vehicle"
:max-dimension="400"
:max-size-mb="0.5"
:readonly-files="['/assets/vehicles/images/bluerov2.png', '/assets/vehicles/images/bb120.png']"
:default-image="require('@/assets/vehicles/images/unknown.svg')"
:image="vehicle_image"
Expand Down Expand Up @@ -34,6 +36,8 @@
<image-picker
size="35px"
directory="/userdata/images/logo"
:max-dimension="400"
:max-size-mb="0.5"
:default-image="require('@/assets/img/blue-robotics-logo.svg')"
:image="logo_image"
@image-selected="save_logo"
Expand Down