AI Image Aspect Ratio Calculator

Share:

AI image dimensions for any aspect ratio — width, height, megapixels and the Midjourney --ar flag, snapped to multiples of 64. Free, in your browser.

RT-AI-019 · AI Tools
Your browser is too old for this tool’s interactive features. Please update to Safari 13.1, Chrome or Edge 80, Firefox 74 or newer.

AI Image Aspect Ratio Calculator

Aspect ratio
—Width (px)
—Height (px)
—Actual ratio
—Megapixels
—Shape error vs requested
—Nearest SDXL training size
—Midjourney flag (your ratio)
Copy the generation size

Dimensions are snapped to whole multiples so they line up with the model's latent grid; the shape error says how far snapping moved the frame from the ratio you asked for. The Midjourney flag is your requested ratio in whole numbers — Midjourney chooses its own pixel size. Everything is computed in your browser — nothing is sent anywhere.

Advertisement
After tool · AD-W1Responsive · Post-tool

How to Use the AI Image Aspect Ratio Calculator

Pick an aspect ratio

Tap a preset like 16:9 or 9:16, or type your own width-to-height ratio into the two number boxes. The ratio is the shape of the frame — it has nothing to do with the final pixel count yet.

Choose a target size

Select a total pixel budget — 1024² (about 1.05 MP) is what SDXL was trained around, 512² what SD 1.5 was — or a base short-edge size such as 512 or 1024. This sets how big the image should be while keeping the shape you chose.

Set the rounding

Pick the grid your generator uses: 64 for SDXL's training sizes, 32 for Black Forest Labs' FLUX API, 16 for FLUX run locally in diffusers, or 8, the smallest step Stable Diffusion accepts. The calculator snaps both edges to it.

Copy the dimensions

Read off the width, height, actual ratio, megapixels, how far snapping moved the shape, the nearest size SDXL was trained on, and the --ar flag for your ratio. Hit Copy to grab the WIDTHxHEIGHT string for Stable Diffusion, ComfyUI, Automatic1111 or any generator that takes explicit pixel sizes.

Advertisement
After how-to · AD-W2Responsive

Why AI Image Dimensions Are Not Just "Any Width and Height"

Aspect ratio sets the shape; megapixels set the detail

When you generate an image with Stable Diffusion, SDXL, FLUX, or Midjourney, you are really choosing two separate things at once: the aspect ratio — the shape of the frame, like 16:9 for a cinematic banner or 9:16 for a phone wallpaper — and the resolution, which is how many total pixels the model paints. People often conflate them, but they are independent. You can render a 16:9 image at half a megapixel or at two megapixels; both are the same shape, but one carries four times the detail. This calculator keeps the two ideas separate on purpose. You lock the ratio with a preset or a custom width-to-height pair, then dial in the total pixel budget in megapixels (or a base short-edge size), and it solves for the exact width and height that satisfy both at the same time.

The arithmetic is simple geometry. If you know the target number of pixels and the ratio of width to height, the width is the square root of (total pixels × ratio) and the height is the square root of (total pixels ÷ ratio). That gives a perfect, fractional answer — but a diffusion model cannot generate 1365.3 pixels. It works on a compressed latent grid, and each model expects each side to be a whole multiple of a fixed number. That is where rounding comes in.

"A clean AI image starts before the prompt: pick the shape, pick the detail budget, then snap both edges to the grid the model actually thinks in."

Which multiple — and what megapixels really buy you

Stable Diffusion and FLUX encode an image into a latent that is eight times smaller on each side, so the hard floor is set by that factor — and it differs by model. The Hugging Face diffusers pipelines for Stable Diffusion and SDXL refuse any width or height not divisible by 8. FLUX packs its latent into 2×2 patches, so diffusers needs multiples of 16 and resizes anything else; Black Forest Labs' own FLUX API asks for multiples of 32, between 256 and 1440 pixels. 64 is not a requirement anywhere, but it is the grid SDXL was trained on: its authors fine-tuned it on aspect-ratio "buckets" that keep the pixel count close to 1024² and vary height and width in multiples of 64. Pick the step your tool uses; the calculator rounds each edge to the nearest multiple rather than handing you the raw fractional number.

The pixel target is where quality and cost meet. SDXL's training sizes all sit near 1024² pixels — about 1.05 megapixels, from 1024×1024 out to 2048×512 — and SD 1.5 was fine-tuned at 512×512, so those budgets match what each model learned from. Push to 1.5 or 2 MP and generation takes longer and uses more memory, and you are asking the model for a canvas larger than anything in its training set; drop to 0.5 MP for fast drafts. The actual ratio, shape error and megapixels readouts matter because rounding shifts the numbers: 16:9 at 1024² snapped to 64 lands on 1344×768, which is really 7:4 — 1.6% narrower than asked, and also exactly one of SDXL's training sizes. The nearest SDXL training size readout names that bucket for any ratio. Finally, Midjourney takes no pixel sizes at all — it takes an aspect-ratio parameter and picks the resolution itself — and its --ar accepts whole numbers only, so the flag here is the ratio you asked for, converted to whole numbers and reduced (2.35:1 becomes --ar 47:20). One tool, two workflows: explicit pixels for the open-source stack, the --ar flag for Midjourney.

Aspect ratio sets the shape; megapixels set the detail

01

Stable Diffusion and FLUX work on a latent grid 8× smaller per side, so pixel sizes must align to it.

02

The diffusers Stable Diffusion and SDXL pipelines refuse a width or height not divisible by 8; FLUX there needs 16.

03

SDXL was fine-tuned on 40 sizes, all multiples of 64 and all near 1024² pixels — from 2048×512 to 512×2048.

04

SD 1.5 was fine-tuned at 512×512, so it does best when the short edge stays close to 512.

05

Aspect ratio sets the shape; megapixels set the detail — they are completely independent.

06

Midjourney takes no pixel sizes — its --ar takes whole numbers only: 139:100, not 1.39:1.

07

Black Forest Labs' FLUX API takes widths and heights in multiples of 32, from 256 to 1440 pixels.

08

Rounding to the grid shifts the numbers, so the actual ratio can differ from the one you asked for — 16:9 at SDXL's budget comes out as 1344×768, really 7:4.

09

More megapixels means more memory and time — and past the training budget, a canvas the model never saw.

10

This calculator does pure arithmetic in your browser — no model, no upload, no network call.

📅 Research current as of 25 Oct 2026 · Sources: Podell et al. 2023, SDXL (arXiv:2307.01952) §2.3 and App. I training sizes; Midjourney Docs, Aspect Ratio; Black Forest Labs API reference, FLUX.1 [dev] (multiples of 32, 256–1440); Hugging Face diffusers Stable Diffusion, SDXL and FLUX pipelines (divisible by 8 / 16).
Standards, published formulas, and reference data are revised over time — check against a current authoritative source before relying on these figures.

Frequently Asked Questions

  • Not strictly. Stable Diffusion and FLUX compress the image into a latent 8× smaller on each side, so the true floors are smaller: the diffusers Stable Diffusion and SDXL pipelines raise an error unless both sides divide by 8, FLUX there needs 16, and Black Forest Labs' FLUX API asks for multiples of 32. 64 matters for SDXL because it was fine-tuned on sizes in multiples of 64 near 1024² pixels, so those sizes are the ones it knows best.
  • Aspect ratio is the shape of the frame (16:9, 1:1, 9:16). Megapixels are the total pixel count — how much detail the model paints. They're independent: you can render the same 16:9 shape at 0.5 MP or 2 MP. This tool lets you fix the ratio and then choose the megapixel budget separately.
  • Midjourney doesn't accept explicit pixel dimensions — the final size depends on the model version and upscaler, and you steer only the shape. The --ar W:H parameter (for example --ar 16:9) sets that shape, and it takes whole numbers only: Midjourney's own example is 139:100 rather than 1.39:1. This calculator converts the ratio you asked for — not the snapped pixel size — to whole numbers in lowest terms, so you can paste it straight into a prompt.
  • Use the 1024² option (about 1.05 MP). SDXL's paper says it was fine-tuned on aspect-ratio buckets that keep the pixel count as close to 1024² as possible, so that budget — 1024×1024 and its ratio variants, such as 1344×768 for 16:9 — matches what it learned from. The "nearest SDXL training size" readout names the exact bucket for your ratio. Going to 1.5 or 2 MP costs memory and time and asks for a canvas larger than any it was trained on.
  • Because each edge is rounded to a whole multiple of the step, the final width and height may not reduce to the exact ratio you typed. The calculator shows the true resulting ratio and the shape error, so you know precisely what the model will generate: 16:9 at 1024² on a 64 grid becomes 1344×768, which is 7:4 and 1.6% narrower. A finer step (16 or 8) usually shrinks the error.
  • The one your generator uses. 64 lands on SDXL's own training grid; 32 is what Black Forest Labs' FLUX API asks for; 16 is the FLUX minimum in diffusers; 8 is the Stable Diffusion minimum in diffusers, and the finest. A multiple of 64 is also a multiple of 32, 16 and 8, so if one size must work everywhere, 64 is the safe choice.
  • Instead of targeting a total megapixel count, the base option fixes the shorter side to a set length (512, 768, 1024, 1536) and scales the longer side to match your ratio. It's handy when a model has a known native short-edge size, such as 512 for SD 1.5. Note that the long side then grows with the ratio, so the pixel count does too — a 9:16 frame on a 1024 short edge is 1024×1792, about 1.8 MP, well past SDXL's 1024² budget.
  • Yes. Type any width and height into the two number boxes, decimals included — for example 2.35 and 1 for an ultra-wide cinema frame. The calculator solves for dimensions that match your custom ratio while still hitting the pixel or base-size target and snapping to the grid, and writes the Midjourney flag in whole numbers (2.35:1 becomes --ar 47:20).
  • Yes. Both take explicit width and height in pixels, so copy the WIDTHxHEIGHT value (or read the separate fields) into the empty-latent or txt2img size inputs. A multiple of 64 also divides by 32, 16 and 8, so one such size stays valid across SD, SDXL and FLUX checkpoints alike.
  • No. Every figure is computed with plain JavaScript arithmetic in your browser. There's no model, no network request, and nothing is stored — the tool works the same whether you're online or offline.

Method & sources

How it computes

For ratio W:H (a = W/H) and pixel budget P: width = √(P·a), height = √(P/a); for a fixed short edge S the long side is S·a. Each edge rounds to the nearest multiple of the chosen grid — 64 (SDXL training sizes), 32 (BFL FLUX API), 16 (FLUX in diffusers) or 8 (Stable Diffusion floor). The Midjourney --ar is the requested ratio in whole numbers, reduced; the nearest of SDXL's 40 training sizes is chosen on log aspect (AiImageSizeKernel).

What this tool implements

  • SDXL's budget and grid are its authors' own: fine-tuned on aspect-ratio buckets "where we keep the pixel count as close to 1024² pixels as possible, varying height and width accordingly in multiples of 64" (Podell et al. 2023, §2.3), with the 40 sizes of Appendix I transcribed as printed. The default target is 1024² ≈ 1.05 MP, not 1,000,000 px.
  • The grid floors come from the code that enforces them: the diffusers Stable Diffusion and SDXL pipelines raise an error unless height and width are divisible by 8; FluxPipeline needs vae_scale_factor × 2 = 16 because latents are packed in 2×2 patches; Black Forest Labs' FLUX.1 [dev] API takes widths and heights that are multiples of 32, from 256 to 1440.
  • Midjourney takes no pixel sizes and its --ar "cannot contain decimals" (Midjourney Docs, Aspect Ratio), so the flag is the REQUESTED ratio scaled to whole numbers (up to four decimals) and reduced — 16:9 stays 16:9, 2.35:1 becomes 47:20 — never the snapped pixels.
  • Rounding moves the shape, and the page says by how much: the shape error is (snapped W/H ÷ requested W/H − 1) × 100; 16:9 at 1024² on the 64 grid is 1344×768, 7:4, −1.56%.
  • Corrected 2026-10-25: --ar was the snapped ratio (16:9 printed --ar 7:4); "21:12" (unreduced) → 7:4; "1 MP (SDXL native)" → 1024² ≈ 1.05 MP; "awkward sizes … invite an outright error" → errors only off the 8 (SD) or 16 (FLUX) grid; the unsourced "duplicated limbs" claim removed. Added: 32 and 16 grids, the shape error and the nearest SDXL training size.

Sources

What can make this go out of date

  • None at runtime; the arithmetic runs in the browser and nothing is sent anywhere.
Advertisement
Pre-footer · AD-W3 728 × 90