Skip to content

Commit 2a0412b

Browse files
author
Caesar0815
committed
add image to background layer with original size if not defined
1 parent 2bdc443 commit 2a0412b

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

components/popups/AddImage.vue

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,26 @@ export default {
159159
},
160160
methods: {
161161
addObject() {
162-
if (this.inputs.type === "Image")
163-
loadImage({
164-
"pos": {
165-
"x": parseInt(this.inputs.x || "0"),
166-
"y": parseInt(this.inputs.y || "0"),
167-
"width": parseInt(this.inputs.width || "120"),
168-
"height": parseInt(this.inputs.height || "120"),
169-
},
170-
"draggable": true,
171-
"snapToGrid": this.inputs.snapToGrid,
172-
"type": "rect",
173-
"src": this.inputs.url,
174-
"rotation": parseInt(this.inputs.rotation || "0"),
175-
"color": this.inputs.color,
176-
});
177-
else
162+
if (this.inputs.type === "Image") {
163+
let image = new Image();
164+
image.onload = () => {
165+
loadImage({
166+
"pos": {
167+
"x": parseInt(this.inputs.x || "0"),
168+
"y": parseInt(this.inputs.y || "0"),
169+
"width": parseInt(this.inputs.width || image.width + ""),
170+
"height": parseInt(this.inputs.height || image.height + ""),
171+
},
172+
"draggable": true,
173+
"snapToGrid": this.inputs.snapToGrid,
174+
"type": "rect",
175+
"src": this.inputs.url,
176+
"rotation": parseInt(this.inputs.rotation || "0"),
177+
"color": this.inputs.color,
178+
});
179+
};
180+
image.src = this.inputs.url;
181+
} else
178182
loadRect({
179183
"pos": {
180184
"x": parseInt(this.inputs.x || "0"),
@@ -198,15 +202,3 @@ export default {
198202
<style scoped lang="scss">
199203
@import "assets/css/scheme";
200204
</style>
201-
{
202-
"pos": {
203-
"x": object.x(),
204-
"y": object.y(),
205-
"width": object.width() * object.getTransform().getMatrix()[0],
206-
"height": object.height() * object.getTransform().getMatrix()[3]
207-
},
208-
"snapToGrid": object.snapToGrid,
209-
"type": "rect",
210-
"color": object.fill(),
211-
"rotation": object.rotation()
212-
}

0 commit comments

Comments
 (0)