A WordPress plugin which automatically uses an edge transformation service (e.g., Cloudflare or Accelerated Domains) to apply performance optimizations to <img>
markup.
- Automatic image optimization through edge providers
- Smart
srcset
generation for responsive images - Support for multiple CDN/edge providers
- Automatic WebP/AVIF conversion (provider dependent)
- Yoast SEO integration for meta images
- No local image processing required
- No additional server load
- Maintains original images
- WordPress: 5.6 or higher
- PHP: 7.4 or higher
- Gutenberg: Full support for image blocks
- Classic Editor: Full support
- Author: Jono Alderson
Edge Images filters image blocks and template functions (such as wp_get_attachment_image()
and get_the_post_thumbnail()
), and:
- Alters
src
andsrcset
attributes to use the edge provider's URL format. - Generates comprehensive
srcset
values, optimalsizes
attributes, and applies general image optimizations. - Wraps the
<img>
in a<picture>
elem (optional).
WordPress ships with a concept of "image sizes", each of which has a height, width and crop option. It provides some defaults like 'large', 'medium' and 'thumbnail', and provides ways for developers to customize or extend these options. When a user adds images to content, or includes them in templates, they must select the most optimal size from the options available.
This is often imprecise. Images are often loaded at 'roughly the right size', then shunk or stretched by the browser; by varying degrees of inaccuracy based on the user's context (such as viewport size, screen density, or content preferences). This is inefficient, and 'expensive' from a performance perspective.
WordPress attempts to mitigate this by generating srcset
and sizes
values in image markup. However, the accuracy of this is limited by the availability and size of pre-generated images - which is rarely sufficient.
This plugin solves these problems by providing suitable 'interstitial' srcset
values, generated on-demand via an edge provider, without the need to pre-generate a large number of images.
- PHP 7.0+
- Domain must be served through a supported edge provider, with image resizing features available and enabled.
- Supported edge providers are:
- Cloudflare, with the 'Image resizing' feature enabled (note that this requires a Pro account or higher).
- Accelerated Domains, with the 'Image resizing' feature enabled.
- BunnyCDN, with the 'Image resizing' feature enabled.
PHP
echo wp_get_attachment_image(1, [640,400], false, ['fit' => 'contain', 'gravity' => 'left']);
HTML output: Before
<img width="380" height="400" src="http://edge-images-plugin.local/wp-content/uploads/2024/11/1.jpg" class="attachment-640x400 size-640x400" alt="" fit="contain" gravity="left" decoding="async" loading="lazy" srcset="http://edge-images-plugin.local/wp-content/uploads/2024/11/1.jpg 400w, http://edge-images-plugin.local/wp-content/uploads/2024/11/1-285x300.jpg 285w" sizes="auto, (max-width: 380px) 100vw, 380px">
HTML output: After
<picture class="edge-images-container contain" style="aspect-ratio: 8/5; --max-width: 640px;"><img width="640" height="400" src="http://edge-images-plugin.local/acd-cgi/img/v1/wp-content/uploads/2024/11/1.jpg?dpr=1&f=auto&fit=contain&gravity=left&height=400&q=85&width=640" class="attachment-640x400 size-640x400 edge-images-img edge-images-processed" alt="" decoding="async" loading="lazy" srcset="http://edge-images-plugin.local/acd-cgi/img/v1/wp-content/uploads/2024/11/1.jpg?dpr=1&f=auto&fit=contain&gravity=left&height=188&q=85&width=300 300w, http://edge-images-plugin.local/acd-cgi/img/v1/wp-content/uploads/2024/11/1.jpg?dpr=1&f=auto&fit=contain&gravity=left&height=200&q=85&width=320 320w, http://edge-images-plugin.local/acd-cgi/img/v1/wp-content/uploads/2024/11/1.jpg?dpr=1&f=auto&fit=contain&gravity=left&height=400&q=85&width=640 640w, http://edge-images-plugin.local/acd-cgi/img/v1/wp-content/uploads/2024/11/1.jpg?dpr=1&f=auto&fit=contain&gravity=left&height=600&q=85&width=960 960w, http://edge-images-plugin.local/acd-cgi/img/v1/wp-content/uploads/2024/11/1.jpg?dpr=1&f=auto&fit=contain&gravity=left&height=800&q=85&width=1280 1280w, http://edge-images-plugin.local/acd-cgi/img/v1/wp-content/uploads/2024/11/1.jpg?dpr=1&f=auto&fit=contain&gravity=left&height=1000&q=85&width=1600 1600w" sizes="(max-width: 640px) 100vw, 640px" data-attachment-id="11"></picture>
The plugin automatically converts WordPress' native image sizes, any sizes registered via add_image_size()
, and array values.
The plugin automatically integrates with the following systems and plugins.
Automatically transforms images in:
- Meta tags (e.g.,
og:image
and similar) - Schema.org JSON-LD output (currently for the 'primary image of page' property only)
- XML sitemaps
Supports the following filters:
edge_images_yoast_disable
(bool
): Disables the Yoast SEO integration. Defaults tofalse
.edge_images_yoast_disable_schema_images
(bool
): Disables filtering images output in Yoast SEO schema. Defaults tofalse
.edge_images_yoast_disable_xml_sitemap_images
(bool
): Disables filtering images output in Yoast SEO XML sitemaps. Defaults tofalse
.edge_images_yoast_disable_social_images
(bool
): Disables filtering images output in Yoast social images (og:image
andtwitter:image
). Defaults tofalse
.edge_images_yoast_social_image_args
: (array
): Alters the args passed to the social image.
When using wp_get_attachment_image()
or similar functions, you can pass the following attributes to control image transformation:
width
orw
: Width of the image in pixelsheight
orh
: Height of the image in pixelsfit
: Resizing behavior. Supported values:contain
: Resize to fit within dimensions while maintaining aspect ratiocover
: Resize to cover dimensions while maintaining aspect ratiocrop
: Crop to exact dimensionsscale-down
: Scale down to fit within dimensionspad
: Pad to exact dimensions
gravity
org
: Crop/focus position. Supported values:auto
: Automatic focus detectioncenter
: Center of imagenorth
: Top edgesouth
: Bottom edgeeast
: Right edgewest
: Left edgeleft
: Left sideright
: Right side
quality
orq
: JPEG/WebP quality (1-100). Defaults to 85format
orf
: Output format. Supported values:auto
: Automatically select best format (default)webp
: Force WebP formatjpeg
: Force JPEG formatpng
: Force PNG formatavif
: Force AVIF format
dpr
: Device Pixel Ratio multiplier (1-3)metadata
: Metadata handling. Supported values:keep
: Preserve all metadatacopyright
: Keep only copyright infonone
: Strip all metadata
blur
: Apply Gaussian blur (1-250)sharpen
: Apply sharpening (1-100)brightness
: Adjust brightness (-100 to 100)contrast
: Adjust contrast (-100 to 100)gamma
: Adjust gamma correction (1-100)
echo wp_get_attachment_image(
$attachment_id,
[800, 600],
false,
[
'fit' => 'contain',
'gravity' => 'center',
'quality' => 90,
'sharpen' => 1
]
);
This will output an 800x600 image that:
- Fits within the dimensions while maintaining aspect ratio
- Is centered in the frame
- Uses 90% JPEG quality
- Has slight sharpening applied
All parameters are optional and will use sensible defaults if not specified.
- Upload the plugin files to
/wp-content/plugins/edge-images/
- Activate the plugin through the 'Plugins' screen in WordPress
- Go to Settings > Edge Images to configure your provider
- Ensure your domain is on a Cloudflare Pro plan or higher
- Enable "Image Resizing" in your Cloudflare dashboard
- Select "Cloudflare" in the Edge Images settings
- Enable image optimization in your Accelerated Domains dashboard
- Select "Accelerated Domains" in the Edge Images settings
- Enable image processing in your Bunny CDN dashboard
- Select "Bunny CDN" in the Edge Images settings
- Create an Imgix source for your domain
- Enter your Imgix subdomain in the Edge Images settings
- Select "Imgix" in the Edge Images settings
edge_images_disable
(bool
): Disable all image transformation. Defaults tofalse
.edge_images_provider
(string
): Override the selected provider. Accepts 'cloudflare', 'accelerated_domains', 'bunny', or 'imgix'.edge_images_domain
(string
): Override the domain used for image URLs. Defaults to site URL.edge_images_disable_picture_wrap
(bool
): Disable wrapping images in<picture>
elements. Defaults tofalse
.
edge_images_max_width
(int
): Maximum width for generated images. Defaults to 2400.edge_images_min_width
(int
): Minimum width for generated images. Defaults to 300.edge_images_quality
(int
): Default JPEG/WebP quality. Defaults to 85.
edge_images_preloads
(array
): Array of image IDs and sizes to preload.
- Check that your chosen provider is properly configured
- Verify that image resizing is enabled in your provider's dashboard
- Check the browser console for any JavaScript errors
- Try disabling other image optimization plugins
- Consider enabling browser caching for transformed images
- Use the
edge_images_preloads
filter for critical images - Adjust quality settings for better compression
- 404 Errors: Ensure your provider's image transformation service is properly enabled
- Broken Images: Check that image paths are correctly formatted
- Missing Transformations: Verify that your provider supports the requested transformations