Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Price Validation Assistant): fix image display #1152

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions src/components/ContributionAssistantPriceFormCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
<v-divider />
<v-card-text>
<v-img
v-if="mode === 'Contribution'"
class="mb-4"
height="200px"
:src="productPriceForm.proofImage"
contain
/>
<ProofImageCropped v-else-if="mode === 'Validation'" :proofImageFilePath="productPriceForm.proofImage" :boundingBox="productPriceForm.bounding_box" />
<ProductInputRow :productForm="productPriceForm" :disableInitWhenSwitchingType="true" @filled="productFormFilled = $event" />
<v-alert
v-if="productIsTypeProduct"
Expand Down Expand Up @@ -72,6 +74,7 @@ import constants from '../constants'

export default {
components: {
ProofImageCropped: defineAsyncComponent(() => import('../components/ProofImageCropped.vue')),
ProductInputRow: defineAsyncComponent(() => import('../components/ProductInputRow.vue')),
PriceInputRow: defineAsyncComponent(() => import('../components/PriceInputRow.vue')),
ProofFooterRow: defineAsyncComponent(() => import('../components/ProofFooterRow.vue')),
Expand Down
54 changes: 54 additions & 0 deletions src/components/ProofImageCropped.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<template>
<v-img
height="200px"
:src="croppedImage"
contain
/>
</template>

<script>
export default {
props: {
proofImageFilePath: {
type: String,
default: ''
},
boundingBox: {
type: Array,
default: () => []
}
},
data() {
return {
canvas: null,
ctx: null,
proofImage: null,
croppedImage: null
}
},
mounted() {
this.getImage()
},
methods: {
getImage() {
this.canvas = document.createElement('canvas')
this.ctx = this.canvas.getContext('2d')
this.proofImage = new Image()
this.proofImage.onload = this.cropImage
this.proofImage.src = `${import.meta.env.VITE_OPEN_PRICES_APP_URL}/img/${this.proofImageFilePath}`
this.proofImage.crossOrigin = 'Anonymous'
},
cropImage() {
console.log(this.proofImage.complete)
const { startX, startY, endX, endY } = this.boundingBox
raphodn marked this conversation as resolved.
Show resolved Hide resolved
const width = Math.abs(endX - startX)
const height = Math.abs(endY - startY)
this.canvas.width = width
this.canvas.height = height
this.ctx.drawImage(this.proofImage, Math.min(startX, endX), Math.min(startY, endY), width, height, 0, 0, width, height)
this.croppedImage = this.canvas.toDataURL()
console.log(this.croppedImage)
}
}
}
</script>
1 change: 1 addition & 0 deletions src/views/PriceValidatorAssistant.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export default {
// proofImage: 'https://prices.openfoodfacts.org/img/0024/2NToLMxOgN.webp',
product_code: barcodeString,
detected_product_code: barcodeString,
bounding_box: data.items[i].bounding_box
}
this.productPriceForms.push(productPriceForm)
}
Expand Down
Loading