Skip to main content

filter · Image filters

Insert image dimensions (insert_img_dimensions)

Category:
Image
CoreFilters:
No
OptimizeForBandwidth:
No
Risk:
Generally safe

insert_image_dimensions adds explicit width and height attributes to <img> tags that lack them. This prevents layout shifts (CLS) but does not resize the image file itself. insert_img_dimensions is an accepted alternate spelling of the same filter.

When to use it

  • An alternate spelling of insert_image_dimensions: the module accepts both names for the same filter.
  • Not in CoreFilters: it runs only when you enable it by name.
  • Risk rating on these docs: Generally safe.

Risks

The Image filters page lists no specific risks for this filter. If a page misbehaves with it, DisableFilters insert_img_dimensions turns it off for the scope you set it in.

Configuration

Enable it in the module configuration, at server, virtual-host or location scope:

Apache

ModPagespeedEnableFilters insert_img_dimensions

nginx

pagespeed EnableFilters insert_img_dimensions;

IIS (pagespeed.config)

pagespeed EnableFilters insert_img_dimensions
ParameterDefaultDescription
ImageLimitResizeAreaPercent100Only resize if the result is this percentage of the original area or less

Scoping, ForbidFilters and the thresholds filters read: Choosing filters.

Frequently asked questions

What is the insert_img_dimensions filter?
insert_img_dimensions is an alternate spelling of insert_image_dimensions that the module accepts. Both names enable the same filter.
Is insert_img_dimensions enabled by default?
No. insert_img_dimensions is not in CoreFilters, the default RewriteLevel; it runs only when you enable it by name with EnableFilters.
How do I enable insert_img_dimensions on Apache and nginx?
Add ModPagespeedEnableFilters insert_img_dimensions on Apache or pagespeed EnableFilters insert_img_dimensions; on nginx. On IIS, add pagespeed EnableFilters insert_img_dimensions to pagespeed.config.

This page is drawn from the insert_img_dimensions entry on Image filters. Every filter in one table: PageSpeed filters.

Search