Fix size props in ImagePicker

This commit is contained in:
Johannes Zellner
2025-11-07 12:04:48 +01:00
parent 27f975f3c5
commit 232bce0a2d
4 changed files with 11 additions and 14 deletions
+8 -11
View File
@@ -10,8 +10,8 @@ const props = defineProps({
mode: { type: String, default: 'editable', required: true },
src: { type: String, required: true },
fallbackSrc: { type: String, required: true },
size: { type: String, required: true },
maxSize: { type: String, required: false },
size: { type: Number, required: false, default: 512 },
maxSize: { type: Number, required: false, default: 0 },
displayHeight: { type: String, required: false },
displayWidth: { type: String, required: false },
disabled: { type: Boolean, required: false },
@@ -109,22 +109,19 @@ function onChanged(event) {
fr.onload = function () {
const image = new Image();
image.onload = function () {
const size = props.size ? parseInt(props.size) : 512;
const maxSize = props.maxSize ? parseInt(props.maxSize) : 0;
const canvas = document.createElement('canvas');
if (maxSize) {
if (image.naturalWidth > maxSize) {
canvas.width = maxSize;
canvas.height = (image.naturalHeight / image.naturalWidth) * maxSize;
if (props.maxSize) {
if (image.naturalWidth > props.maxSize) {
canvas.width = props.maxSize;
canvas.height = (image.naturalHeight / image.naturalWidth) * props.maxSize;
} else {
canvas.width = image.naturalWidth;
canvas.height = image.naturalHeight;
}
} else {
canvas.width = size;
canvas.height = size;
canvas.width = props.size;
canvas.height = props.size;
}
const imageDimensionRatio = image.width / image.height;