For developers
imgTag filter
The imgTag filter is a Liquid helper that renders a full <img> tag from an Image input. It is the quickest way to output a resized image with email-safe width and height attributes.
What imgTag does
When you use imgTag, Better Email:
- outputs an
<img>tag - uses the image metadata stored on the input
- applies resizing rules to the
src - includes width and height styling for more predictable rendering
If the image input has built-in alt text enabled, imgTag uses the stored altText value automatically unless you override it.
Basic example
{{ my_module.my_image | imgTag }}
Tag parameters
These parameters control the generated <img> tag itself:
altText: override the stored alt text valueclass: add CSS classesstyle: append custom inline stylesresize: set tofalseto skip resizing and use the original image URL (default:true)
Resize parameters
These parameters control how the image is resized. We use Cloudflare Images transformations behind the scenes, so the parameters follow Cloudflare's semantics.
width: override the width from the image input options. When onlywidthis given, the height is auto-calculated to preserve the aspect ratio.height: set an explicit heightdpr: override the input's device pixel ratio. Usedpr: 2for crisp images on high-DPI/Retina screens.fit: control how width and height are interpreted during resizing (default:cover). See fit modes below.gravity: crop anchor when cropping —auto,face,center,top,bottom,left,right. Usefaceto keep detected faces in frame.flip: mirror the image horizontally withh, vertically withv, or both withhv. Flip is applied beforerotate.zoom: control how tightly Cloudflare crops around a detected face, from0(include the most background) to1(crop most closely to the face). This only works withgravity: 'face'; it is not a general-purpose zoom control.background: background color, typically used withfit: 'pad'. Whenfitispadand no background is set, it defaults to transparent.blur: blur amount from0to250brightness: brightness adjustment from0to100contrast: contrast adjustment from0to100gamma: gamma adjustment from0to100sharpen: sharpening strength from0to10rotate: rotate the image by90,180, or270degreesanim: set totrueto preserve animation frames in animated images (GIFs). Cannot be combined withmask.mask: cut the image to a shape — see Masks belowquality: output quality from1to100format: force an output format —avif,webp, orjson. A masked image is always a PNG, soavifandjsoncannot be combined withmask.metadata: control image metadata in the output —keep,copyright, ornonetrim_top/trim_left/trim_right/trim_bottom: cut off pixels from the given edge before resizing
Fit modes
cover(default): resize the image to fill the entire area of the given width and height. If the aspect ratio differs, the image is cropped to fit.scale-down: likecontain, but the image is never enlarged. If the image is larger than the given width or height it is resized; otherwise its original size is kept.crop: shrink and crop the image to fit within the given width and height, but never enlarge it. For smaller images this behaves likescale-down; for larger images it behaves likecover.pad: resize the image to the maximum size that fits within the given width and height, then fill the remaining area with thebackgroundcolor (transparent by default). A good choice for logos when you know the background color.contain: avoid withimgTag. The tag styles the image to the exact requested width and height, so a contained image gets stretched and appears distorted. Usescale-down,pad, orcoverinstead. (containis fine with the resizeImage filter when you control the HTML yourself.)
Advanced example
{{ my_module.my_image | imgTag: width: 200, height: 150, dpr: 2, fit: 'cover', style: 'border: 1px solid red;', class: 'my-image', altText: 'My Image' }}
Possible output:
<img alt="My Image" class="my-image" src="..." height="150" style="width: 200px; height: 150px; border: 1px solid red;" />
Flip and face-aware cropping
Mirror an image horizontally while keeping the detected face in frame:
{{ profile.photo | imgTag: width: 320, height: 320, fit: 'cover', gravity: 'face', zoom: 0.5, flip: 'h' }}
Use flip: 'v' for a vertical flip or flip: 'hv' for both directions. Face zoom accepts decimal values from 0 through 1 and requires gravity: 'face'; invalid combinations are rejected.
Masks
Use mask to cut an image to a shape: rounded corners, a circle, or any outline you supply. The shape is cut into the image itself as real transparency, so it renders correctly in every email client, on any background colour, in both light and dark mode.
{{ my_module.my_image | imgTag: width: 600, mask: "rounded", mask_radius: 16 }}
The output is a normal <img> tag — masking changes the image, not the markup, so nothing else about your template has to change:
<img alt="Spring sale" class="" src="..." height="300" style="width:600px; height: 300px; " />
Use mask rather than CSS border-radius. Outlook on Windows ignores border-radius and shows square corners. Because a mask is cut into the image itself, the shape survives everywhere — on any background colour, in light and dark mode, in every client.
Mask parameters
mask: the shape —rounded,circle,squircle, orurlmask_radius: corner radius in pixels, formask: "rounded". Either a single number, or four comma-separated numbers as a string for per-corner control.mask_url: URL of an image to use as the mask, required formask: "url"mask_invert: set totrueto cut the shape out of the image instead of keeping it

Left to right: rounded, circle, squircle, and a custom url mask. The cut-away areas are transparent, so they take on whatever is behind the image.
Rounded corners
A single radius rounds all four corners:
{{ hero.image | imgTag: width: 600, mask: "rounded", mask_radius: 16 }}
Four comma-separated values set each corner individually, clockwise from the top left — top-left, top-right, bottom-right, bottom-left. This rounds only the top corners, the usual shape for an image sitting above a coloured content block:
{{ card.image | imgTag: width: 600, mask: "rounded", mask_radius: "16,16,0,0" }}
Radii that are too large for the image are scaled down proportionally rather than rejected, so a very large radius gives you a pill shape.
Circles
circle fits an ellipse inside the image box. Pass a matching width and height for a true circle — a common pattern for author avatars, where gravity: 'face' keeps the face centred:
{{ author.photo | imgTag: width: 96, height: 96, fit: 'cover', gravity: 'face', mask: "circle" }}
Squircles
squircle gives a superellipse. A rounded corner is an arc spliced onto a straight edge, and the join is where the eye sees a corner; on a squircle the curve eases into the edge instead, so there is no join to see. It reads noticeably softer than rounded, and it takes no radius — the curve is derived from the image size.
{{ feature.image | imgTag: width: 600, height: 400, mask: "squircle" }}
Custom shapes
mask: "url" uses any image as the mask. White areas of the mask keep the image, black areas remove it, and greys give partial transparency for soft edges:
{{ hero.image | imgTag: width: 600, mask: "url", mask_url: "https://assets.better.email/brand/blob-mask.png" }}
The mask is stretched to the image dimensions, so it works best when its aspect ratio matches. A mask with a transparent background works the same as one with a black background.
Cutting a shape out
mask_invert: true reverses any mask — the shape is removed and everything around it is kept. This punches a circular hole through the middle of the image:
{{ hero.image | imgTag: width: 600, height: 300, mask: "circle", mask_invert: true }}
Things to know
- Masked images are PNGs. Transparency requires it. For a photograph a PNG is several times the size of the equivalent JPEG, so use
maskwhere the shape matters rather than adding it to every image. See Handle large images. - Animated GIFs cannot be masked. Masking flattens the image to a single frame, so
maskandanim: truecannot be combined. format: 'avif'andformat: 'json'cannot be combined withmask, since the output is always a PNG.resize: falseskips masking, along with every other resize parameter, because it uses the original image URL untouched.
Draw overlays
The draw parameters place one or more overlay images on top of the resized image — for example a logo watermark, a badge, or a tiled pattern. The overlay is composited into the final image itself, so it works in every email client without any CSS positioning tricks.
You can add up to four overlays by numbering the parameter prefixes: draw1_, draw2_, draw3_, and draw4_. Overlays are drawn in order, so draw2_ renders on top of draw1_. (The unnumbered draw_ prefix is also supported for a single overlay, but prefer the numbered form.)
Each overlay supports the following parameters (shown here for draw1_):
draw1_url: URL of the overlay image (required for the overlay to render)draw1_width/draw1_height: overlay dimensionsdraw1_fit: how the overlay is resized within its dimensions —scale-down,contain,cover,crop,paddraw1_gravity: where the overlay is anchored —auto,center,top,bottom,left,rightdraw1_top/draw1_left/draw1_bottom/draw1_right: positional offsets in pixels from the given edgedraw1_opacity: overlay opacity from0to1draw1_repeat: tile the overlay —true(both directions),"x"(horizontally), or"y"(vertically)draw1_background: background color for the overlay layerdraw1_rotate: rotate the overlay by90,180, or270degrees
Example: centered watermark
Place a semi-transparent logo in the center of a hero image:
{{ hero.image | imgTag: width: 640, height: 320, draw1_url: "https://example.com/logo.png", draw1_width: 160, draw1_gravity: "center", draw1_opacity: 0.9 }}
Example: badge in a corner
Position a badge 20px from the top-left corner:
{{ hero.image | imgTag: width: 640, height: 320, draw1_url: "https://example.com/badge.png", draw1_width: 80, draw1_top: 20, draw1_left: 20 }}
Example: multiple overlays
Combine a watermark with a corner badge — the badge (draw2_) is drawn on top of the watermark (draw1_):
{{ hero.image | imgTag: width: 640, height: 320, draw1_url: "https://example.com/logo.png", draw1_width: 160, draw1_gravity: "center", draw1_opacity: 0.5, draw2_url: "https://example.com/badge.png", draw2_width: 80, draw2_top: 20, draw2_right: 20 }}
Example: tiled pattern
Repeat a small pattern image across the whole image:
{{ hero.image | imgTag: width: 640, height: 320, draw1_url: "https://example.com/pattern.png", draw1_width: 40, draw1_repeat: true, draw1_opacity: 0.2 }}
The draw parameters also work with the resizeImage filter if you need the URL instead of a full tag.
Built-in image alt text
When Alt Text is enabled on an image input, the value is stored on the image itself:
{{ my_module.my_image.altText }}
That means this works out of the box:
{{ my_module.my_image | imgTag }}
And this still overrides the stored value when needed:
{{ my_module.my_image | imgTag: altText: "Override alt text" }}