@@ -10,6 +10,10 @@ Visual image clipping / cropping.
10
10
- [ Consider a donation] ( #Consider-a-donation )
11
11
- [ Panel Usage] ( #Panel-usage )
12
12
- [ Frontend Usage] ( #Frontend-usage )
13
+ - [ Single Image] ( #single-image )
14
+ - [ Multiple Images] ( #multiple-images )
15
+ - [ File Methods] ( #file-methods )
16
+ - [ Responsive: srcset] ( #file-srcset )
13
17
- [ License] ( #License )
14
18
15
19
## Installation
@@ -93,30 +97,38 @@ __Note__: This is only about thumbnail quality in the panel. You don't need to m
93
97
# # Frontend Usage
94
98
How to fetch the images defined in a `image-clip` field.
95
99
Read about the `clip()` method a bit further down.
96
- # ### Multiple Images
100
+
101
+ # ## Single Image
97
102
` ` ` php
98
- foreach($ page->myimages()->toImages() as $image ) {
103
+ if ($image = $ page->myimages()->toImage() ) {
99
104
echo $image->clip(500);
100
105
}
101
106
` ` `
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.
104
109
105
- # ### Single Image
110
+ # ## Multiple Images
106
111
` ` ` php
107
- if ($image = $ page->myimages()->toImage() ) {
112
+ foreach($ page->myimages()->toImages() as $image ) {
108
113
echo $image->clip(500);
109
114
}
110
115
` ` `
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
+
113
119
120
+ # ## File Methods
114
121
115
122
# ### `$file->clip()`
116
123
Clip and resize. Generates a Thumbnail of the clip area.
117
124
118
125
Adapter for `$file->thumb()`. Returns a FileVersion|File Object.
119
126
` ` ` php
127
+ if ($image = $page->myimages()->toImage()) {
128
+ echo $image->clip(500);
129
+ }
130
+ ` ` `
131
+ ` ` ` php
120
132
$file->clip(200, 300); // bestfit
121
133
$file->clip(200); // width 200px
122
134
$file->clip(null, 300); // height 300px
@@ -127,7 +139,17 @@ $file->clip(); // clip area without resizing
127
139
- if `width` and `height` are both defined, the image will be resized with `bestfit`
128
140
129
141
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()`
131
153
The thumb method accepts now the option `clip` and can be used with any resizable image.
132
154
` ` ` php
133
155
$file->thumb([
@@ -146,7 +168,7 @@ $file->thumb([
146
168
147
169
Read more about the `thumb` method in the [Kirby3 Docs](https://getkirby.com/docs/reference/objects/file/thumb)
148
170
149
- # ## Helper `$file->getClip()`
171
+ # ### `$file->getClip()`
150
172
Returns the clip data.
151
173
152
174
Can be useful e.g with the `$file->thumb()` method.
0 commit comments