@@ -10,6 +10,10 @@ Visual image clipping / cropping.
1010- [ Consider a donation] ( #Consider-a-donation )
1111- [ Panel Usage] ( #Panel-usage )
1212- [ Frontend Usage] ( #Frontend-usage )
13+ - [ Single Image] ( #single-image )
14+ - [ Multiple Images] ( #multiple-images )
15+ - [ File Methods] ( #file-methods )
16+ - [ Responsive: srcset] ( #file-srcset )
1317- [ License] ( #License )
1418
1519## Installation
@@ -93,30 +97,38 @@ __Note__: This is only about thumbnail quality in the panel. You don't need to m
9397# # Frontend Usage
9498How to fetch the images defined in a `image-clip` field.
9599Read about the `clip()` method a bit further down.
96- # ### Multiple Images
100+
101+ # ## Single Image
97102` ` ` php
98- foreach($ page->myimages()->toImages() as $image ) {
103+ if ($image = $ page->myimages()->toImage() ) {
99104 echo $image->clip(500);
100105}
101106` ` `
102- - **Important:** ~~toFiles ~~ does not work, use `toImages ()` instead.
103- - ` toImages ()` returns a Files Collection with all it's functions.
107+ - **Important:** ~~toFile ~~ does not work, use `toImage ()` instead.
108+ - ` toImage ()` returns a File Object with all it's functions.
104109
105- # ### Single Image
110+ # ## Multiple Images
106111` ` ` php
107- if ($image = $ page->myimages()->toImage() ) {
112+ foreach($ page->myimages()->toImages() as $image ) {
108113 echo $image->clip(500);
109114}
110115` ` `
111- - **Important:** ~~toFile~~ does not work, use `toImage()` instead.
112- - ` toImage()` returns a File Object with all it's functions.
116+ - **Important:** ~~toFiles~~ does not work, use `toImages()` instead.
117+ - ` toImages()` returns a Files Collection with all it's functions.
118+
113119
120+ # ## File Methods
114121
115122# ### `$file->clip()`
116123Clip and resize. Generates a Thumbnail of the clip area.
117124
118125Adapter for `$file->thumb()`. Returns a FileVersion|File Object.
119126` ` ` php
127+ if ($image = $page->myimages()->toImage()) {
128+ echo $image->clip(500);
129+ }
130+ ` ` `
131+ ` ` ` php
120132$file->clip(200, 300); // bestfit
121133$file->clip(200); // width 200px
122134$file->clip(null, 300); // height 300px
@@ -127,7 +139,17 @@ $file->clip(); // clip area without resizing
127139 - if `width` and `height` are both defined, the image will be resized with `bestfit`
128140
129141
130- # ## Improved `$file->thumb()`
142+ # ### `$file->srcset()`
143+ Use this method to generate the srcset attribute for responsive images.
144+ Read more about it's functionality in the [Kirby3 Docs](https://getkirby.com/docs/guide/templates/resize-images-on-the-fly#responsive-images)
145+ ` ` ` html
146+ <?php if ($image = $page->myimages()->toImage()): ?>
147+ <img srcset="<?= $image->srcset([300, 800, 1024]) ?>">
148+ <?php endif; ?>
149+ ` ` `
150+
151+
152+ # ### `$file->thumb()`
131153The thumb method accepts now the option `clip` and can be used with any resizable image.
132154` ` ` php
133155$file->thumb([
@@ -146,7 +168,7 @@ $file->thumb([
146168
147169Read more about the `thumb` method in the [Kirby3 Docs](https://getkirby.com/docs/reference/objects/file/thumb)
148170
149- # ## Helper `$file->getClip()`
171+ # ### `$file->getClip()`
150172Returns the clip data.
151173
152174Can be useful e.g with the `$file->thumb()` method.
0 commit comments