79
79
* - widths: Comma separated, sorted list of width values to be used in the srcset attribute
80
80
* - type: Indicates how width values should be used (optional, default: w)
81
81
* - w: Values will be used as pixels, e.g. widths="1600,960" results in srcset="... 1600w, ... 960w"
82
- * - x: Values will be used as pixel ration , e.g. widths="1600,960" results in srcset="... 2x, ... 1x"
82
+ * - x: Values will be used as pixel ratio , e.g. widths="1600,960" results in srcset="... 2x, ... 1x"
83
83
* - sizes: Media queries to define image size in relation of the viewport (optional)
84
+ * - formats: Associative array of with format names ('jpeg', 'webp', 'png', 'gif', 'avif', 'jpeg2000') as keys and quality values as values (optional)
84
85
* - useDataAttributes: Boolean indicating whether to replace src, srcset, sizes by data-src, data-srcset, data-sizes (optional, default: __false__)
85
86
* - alt: Alternative text (optional)
86
87
* - class: Image class (optional)
87
- * - title: Image title (optional
88
88
* - data: Associative array of key/value pairs to be used as data attributes
89
89
* - width: Width in pixels to output for the width attribute, the height attribute will be calculated according to the aspect ration (optional)
90
90
* - default: The default file, if src does not exist (optional)
91
91
* - generate: Boolean indicating whether to generate the images or not (optional, default: __false__)
92
- * @param $template Smarty_Internal_Template
92
+ * @param $template \Smarty\Template
93
93
* @return String
94
94
*/
95
- function smarty_function_image ($ params , Smarty_Internal_Template $ template ) {
95
+ function smarty_function_image ($ params , \ Smarty \ Template $ template ) {
96
96
$ file = $ params ['src ' ];
97
97
$ default = isset ($ params ['default ' ]) ? $ params ['default ' ] : '' ;
98
98
$ widths = array_map ('trim ' , isset ($ params ['widths ' ]) ? explode (', ' , $ params ['widths ' ]) : []);
99
99
$ type = isset ($ params ['type ' ]) ? $ params ['type ' ] : 'w ' ;
100
100
$ sizes = isset ($ params ['sizes ' ]) ? $ params ['sizes ' ] : '' ;
101
+ $ formats = isset ($ params ['formats ' ]) && is_array ($ params ['formats ' ]) ? $ params ['formats ' ] : [];
101
102
$ useDataAttributes = isset ($ params ['useDataAttributes ' ]) ? $ params ['useDataAttributes ' ] : false ;
102
103
$ generate = isset ($ params ['generate ' ]) ? $ params ['generate ' ] : false ;
103
104
$ alt = isset ($ params ['alt ' ]) ? $ params ['alt ' ] : '' ;
@@ -106,7 +107,7 @@ function smarty_function_image($params, Smarty_Internal_Template $template) {
106
107
$ data = isset ($ params ['data ' ]) && is_array ($ params ['data ' ]) ? $ params ['data ' ] : [];
107
108
$ width = isset ($ params ['width ' ]) ? $ params ['width ' ] : null ;
108
109
109
- return ImageUtil::getImageTag ($ file , $ widths , $ type , $ sizes ,
110
+ return ImageUtil::getImageTag ($ file , $ widths , $ type , $ sizes , $ formats ,
110
111
$ useDataAttributes , $ alt , $ class , $ title , $ data , $ width , $ default , $ generate );
111
112
}
112
113
?>
0 commit comments