Installation
- Composer:
composer require nelson/resizer
- Register:
extensions:
resizer: Nelson\Resizer\DI\ResizerExtension
-
Config:, (*1)
These are the default values.
Empty values are required., (*2)
resizer:
paths:
wwwDir: '%wwwDir%'
storage:
assets:
cache: '%wwwDir%/cache/images/'
library: 'Imagick'
cacheNS: 'resizer'
absoluteUrls: false
interlace: true
jpeg_quality: 75
webp_quality: 75
png_compression_level: 9
Usage
Order of parameters:, (*3)
- Image file.
string
- Dimensions.
string
- From assets?
bool
- Format.
string
Dimensions
Allowed variants:, (*4)
-
100x100 - width and height must be equal or less, resized according to AR.
-
x100 - height must be equal or less.
-
100x - width must be equal or less.
Modificators:, (*5)
- Cropping:
- width:
l - left, c - center, r - right.
- height:
t - top, c - center, b - bottom.
- Conditional resize:
-
ifresize-100x200 - do not resize if the source is smaller.
- Force dimensions:
-
100x200! - resize to these dimensions, regardless of AR.
Formats:, (*6)
- The fourth parameter can be used to switch between image file formats, e.g.
<source srcset=""> in <picture> tag for converting jpegs to webps.
Types
Insert the src manually:, (*7)
<img src="{rlink 'test.jpg', '200x100'}">
Or there are two new macros - rsrc and rhref:, (*8)
<img n:rsrc="'test.jpg', 'l400xc200'">
<a n:rhref="'test.jpg', 'l400xc200'" target="_blank">Link to image</a>
Links can also be absolute, the usage is just like everywhere in Nette - //., (*9)
Beware of the usage in macro, the slashes need to be outside of the string:, (*10)
<img n:rsrc="//'test.jpg', 'l400xc200'">
<a n:rhref="//'test.jpg', 'l400xc200'" target="_blank">Link to image</a>