diff --git a/docs/assets/hummingbird CC BY-SA 4.0.jpg b/docs/assets/hummingbird CC BY-SA 4.0.jpg new file mode 100644 index 000000000..967146ca4 Binary files /dev/null and b/docs/assets/hummingbird CC BY-SA 4.0.jpg differ diff --git a/docs/assets/img_sample_for_kimg.png b/docs/assets/img_sample_for_kimg.png deleted file mode 100644 index f06c72c46..000000000 Binary files a/docs/assets/img_sample_for_kimg.png and /dev/null differ diff --git a/docs/common/DocsShow.vue b/docs/common/DocsShow.vue index cd1a8acec..97d9b29ae 100644 --- a/docs/common/DocsShow.vue +++ b/docs/common/DocsShow.vue @@ -29,6 +29,20 @@ type: Boolean, required: false, }, + /** + * Container width + */ + width: { + type: String, + required: false, + }, + /** + * Container max width + */ + maxWidth: { + type: String, + required: false, + }, }, computed: { style() { @@ -36,6 +50,8 @@ display: this.block ? 'block' : 'inline-block', padding: this.padding ? '8px 24px' : null, backgroundColor: this.dark ? this.$themePalette.grey.v_500 : undefined, + width: this.width ? this.width : undefined, + maxWidth: this.maxWidth ? this.maxWidth : undefined, }; }, }, diff --git a/docs/pages/kimg.vue b/docs/pages/kimg.vue index 9e738f74f..79e1c8238 100644 --- a/docs/pages/kimg.vue +++ b/docs/pages/kimg.vue @@ -2,6 +2,213 @@ +

+ It displays an image and provides additional functionality to manipulate it such as setting dimensions, aspect ratio, scaling, letterboxing, and more. +

+
+ + +

Note that when setting dimensions of the image in any of the supported ways, the settings is applied to its container rather than the image itself. Depending on the scale type and other settings, the image may be letterboxed. If you need to apply dimensions directly to the image, you can use fitXY scale type. This, and other modes are illustrated in the examples below, where the original image dimensions is 200px wide and 114px heigh.

+ +

Unless you set fixed dimensions, KImg is responsive by default.

+ +

Rendering within inline and block elements

+ +

Inline

+ +

When rendered within an inline element, the image will preserve its original dimensions.

+ + + + + + + + + + + + + +

Block

+ +

When rendered within a block element, by default the image scales to its parent element with the 'centerInside' scale type (see below).

+ + +
+ +
+
+ +
+ +
+
+ +

Dimensions

+ +

You can set the most common dimensions right on the KImg via props like width, maxHeight, etc. See Props for a full list. Values may be either numbers or strings consisting of a numeral and valid units.The following units are supported: %, cm, em, ex, ch, in, lh, mm, px, rem, rlh, vh, vw. If you don't provide a unit, px will be used.

+ + +
+ +
+
+ +

Alternative text

+ +

Alternative text (altText) is required by default. If an image , then set isDecorative to truthy value. Then, alternative text won't be required and the image will be hidden from assistive technologies.

+ + +
+ +
+
+ +

Scaling

+ +

'centerInside' scale type

+ +

Scales the image uniformly and maintains its original aspect ratio so that both its width and height are equal to or less than the container.

+ +

The original aspect ratio is maintained. The image can be letterboxed. It's the safest mode as it never distorts the image.

+ + +
+ +
+
+ +
+ +
+
+ +

'contain' scale type

+ +

Behaves like 'centerInside' except it ensures that at least one axis of the image fits the container exactly.

+ +

The original aspect ratio is maintained. The image can be letterboxed. This mode may distort the image by enlarging it above its original size.

+ + +
+ +
+
+ +
+ +
+
+ +

'fitXY' scale type

+ +

Scales X and Y axis of the image independently, so that the image matches the container exactly.

+ +

This mode may distort the image as its original aspect ratio is ignored and the image won't be letterboxed. It could also distort the image by enlarging it above its original size.

+ + +
+ +
+
+ +
+ +
+
+ +

Aspect ratio

+ +

Note that ratio styles are based on the width information, therefore it needs to be available in some way. For example, it could be provided directly to KImg, or you could ensure that its parent element has width by setting it explicitly or by using a block element.

+ +

You may combine aspect ratio with any of the scale types.

+ + +
+ +
+
+ +
+ +
+
+ +
+
@@ -95,21 +303,23 @@ .img-example-1 { display: flex; + flex-wrap: wrap; margin-top: 20px; } - .img-example-2 { - margin-top: 20px; - margin-bottom: 20px; - } + /* + .img-example-2 { + margin-top: 20px; + margin-bottom: 20px; + } - .img-example-2 > div { - display: flex; - } + .img-example-2 > div { + display: flex; + } - .img-example-2 > div > div { - margin-top: 30px; - } + .img-example-2 > div > div { + margin-top: 30px; + } */ diff --git a/lib/KImg.vue b/lib/KImg.vue index 829e6f5cf..fa3787d41 100644 --- a/lib/KImg.vue +++ b/lib/KImg.vue @@ -1,19 +1,57 @@