customized-fabric 1.6.6 → 1.6.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -50,5 +50,6 @@ export default class ImagePlaceholder extends fabric.Group {
|
|
50
50
|
setImageType?: (type: ImageFilterType) => void;
|
51
51
|
setImageColor?: (color: string) => void;
|
52
52
|
applyImageFilters?: (image: fabric.Image | undefined) => void;
|
53
|
+
fitImage?: (image: fabric.Image, cover?: boolean) => void;
|
53
54
|
constructor(options?: IImagePlaceholderOptions);
|
54
55
|
}
|
@@ -96,13 +96,20 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
|
|
96
96
|
this.fitImage(this.imageObject);
|
97
97
|
this.canvas?.renderAll?.();
|
98
98
|
},
|
99
|
-
fitImage: function (image) {
|
99
|
+
fitImage: function (image, cover = false) {
|
100
100
|
if (image) {
|
101
101
|
const imageScaleX = this.width / (image?.width ?? 1);
|
102
102
|
const imageScaleY = this.height / (image?.height ?? 1);
|
103
|
-
|
104
|
-
|
105
|
-
|
103
|
+
if (cover) {
|
104
|
+
imageScaleX < imageScaleY
|
105
|
+
? image.set({ scaleX: imageScaleY, scaleY: imageScaleY })
|
106
|
+
: image.set({ scaleX: imageScaleX, scaleY: imageScaleX });
|
107
|
+
}
|
108
|
+
else {
|
109
|
+
imageScaleX > imageScaleY
|
110
|
+
? image.set({ scaleX: imageScaleY, scaleY: imageScaleY })
|
111
|
+
: image.set({ scaleX: imageScaleX, scaleY: imageScaleX });
|
112
|
+
}
|
106
113
|
}
|
107
114
|
},
|
108
115
|
getSettings: function (attribute) {
|
@@ -128,7 +135,7 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
|
|
128
135
|
if (index >= 0) {
|
129
136
|
canvas.insertAt(loadedImage, index, false);
|
130
137
|
}
|
131
|
-
this.fitImage(this.uploadedImage);
|
138
|
+
this.fitImage(this.uploadedImage, true);
|
132
139
|
this.applyImageFilters(this.uploadedImage);
|
133
140
|
canvas?.renderAll();
|
134
141
|
}
|