You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to fix getting a blurry image on HTML/CSS to Image API
8
+
Complete guide to understanding and fixing blurry images with pixel density, resolution, and device scaling
9
9
---
10
-
# Debugging blury images
10
+
11
+
# Debugging Blurry Images
11
12
{: .no_toc }
12
13
{: .fs-9 }
13
14
14
-
Troubleshooting guide
15
+
The complete guide to crystal-clear, high-resolution images
15
16
{: .fs-6 .fw-300 }
17
+
16
18
<hr>
17
19
18
20
Table of contents
@@ -22,21 +24,276 @@ Table of contents
22
24
23
25
<hr>
24
26
25
-
## Why is my image blurry?
26
-
If your rendered image looks low quality, the problem can often be solved with a few quick changes.
27
+
## Why Images Look Blurry
28
+
29
+
Blurry images are almost always caused by **insufficient pixel density** for the display they're viewed on. Modern screens—especially smartphones, tablets, and high-resolution monitors—pack many more pixels into the same physical space than older displays.
30
+
31
+
The HTML/CSS to Image API automatically generates **high-resolution images by default** to ensure your images look crisp on all devices. Here's everything you need to know about creating pixel-perfect images.
32
+
33
+
{% include hint.md title="Default High Resolution" text="The HCTI API defaults to 2x resolution (device_scale: 2) for HTML images to prioritize image quality. This ensures your images look sharp on both standard and high-DPI displays." %}
34
+
35
+
## Understanding Pixel Density
36
+
37
+
### The Modern Display Challenge
38
+
39
+
Today's screens vary dramatically in pixel density:
When you create an image at standard resolution (1x) and display it on a high-density screen, the browser must **stretch** those pixels to fill the available space—resulting in a blurry, pixelated appearance.
46
+
47
+
### The 2x Rule Explained
48
+
49
+
The **2x rule** is simple: **create images at double your intended display size**.
50
+
51
+
**Example:**
52
+
- Display size needed: `400×400px`
53
+
- Image source size: `800×800px` (2x)
54
+
- Result: Sharp image on all screens
55
+
56
+
This ensures you have enough pixel data to satisfy high-density displays while still looking great on standard screens.
57
+
58
+
## Device Scale Settings
59
+
60
+
The HCTI API uses the `device_scale` parameter to control image resolution:
61
+
62
+
| Setting | Resolution | Use Case | File Size |
63
+
|---------|------------|----------|-----------|
64
+
|`1`| Standard (1x) | Legacy screens, thumbnails | Smallest |
65
+
|`2`| High (2x) |**Recommended for web**| Medium |
66
+
|`3`| Maximum (3x) | Print, premium displays | Largest |
67
+
68
+
### Default Behavior
69
+
70
+
-**HTML images**: `device_scale: 2` (high resolution by default)
Use SVG for logos and icons that scale perfectly at any resolution:
225
+
```html
226
+
<imgsrc="logo.svg"width="200"height="60">
227
+
<!-- SVG automatically scales to any device -->
228
+
```
229
+
230
+
## Performance Considerations
231
+
232
+
### File Size Impact
233
+
234
+
Higher resolution means larger files:
235
+
-`device_scale: 1` → Base file size
236
+
-`device_scale: 2` → ~4x larger files
237
+
-`device_scale: 3` → ~9x larger files
238
+
239
+
### Optimization Strategies
240
+
241
+
1.**Use appropriate compression**: Balance quality vs. file size
242
+
2.**Choose the right format**:
243
+
- PNG for graphics with transparency
244
+
- JPG for photographs
245
+
- WebP for modern browsers (when supported)
246
+
3.**Consider bandwidth**: Higher resolution may impact load times
247
+
248
+
{% include hint.md title="Performance Tip" text="Use device_scale: 2 as the sweet spot for web usage. It provides excellent quality on all displays while keeping file sizes reasonable." %}
249
+
250
+
## Troubleshooting Checklist
251
+
252
+
When your image still looks blurry:
253
+
254
+
-[ ]**Device scale is set to 2** (for HTML) or explicitly specified (for URLs)
255
+
-[ ]**All source images are 2x their display size**
256
+
-[ ]**External CDN images have high-resolution versions available**
257
+
-[ ]**CSS background images use appropriately sized sources**
258
+
-[ ]**Vector graphics (SVG) are used where possible**
259
+
-[ ]**The generated image is being displayed at the correct size**
0 commit comments