---
canonical: 'https://htmlcsstoimage.com/features/url-to-jpeg/golang'
title: 'Screenshot Webpages as JPEG in GoLang | HTML/CSS to Image'
description: 'Take webpage screenshots as JPEG in GoLang. Capture a URL with viewport, full-page, selector, and browser controls.'
---

# Take JPEG webpage screenshots in GoLang without managing Chrome

Capture public webpages from GoLang without installing Chrome, running chromedp or Rod, or maintaining screenshot storage and delivery.

## Why use the API instead of native GoLang screenshot automation?

- Keep the deployment as a small Go service instead of adding Chrome and a browser-controller process to the runtime.
- Set viewport, full-page, selector, timing, color scheme, and browser-state controls as request parameters instead of browser scripts.
- Receive a hosted .jpeg URL without building a separate pipeline for temporary files, uploads, storage, and delivery.

## Complete GoLang request

Use this request to capture the example webpage as JPEG.

```go
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
    "os"
    "time"
)

func main() {
    request := map[string]any{
        "url": "https://example.com",
        "format": "jpeg",
        "viewport_height": 630,
        "viewport_width": 1200,
    }

    body, err := json.Marshal(request)
    if err != nil {
        panic(err)
    }
    httpRequest, err := http.NewRequest(http.MethodPost, "https://hcti.io/v1/image", bytes.NewReader(body))
    if err != nil {
        panic(err)
    }
    httpRequest.SetBasicAuth(os.Getenv("HCTI_API_ID"), os.Getenv("HCTI_API_KEY"))
    httpRequest.Header.Set("Content-Type", "application/json")

    client := &http.Client{Timeout: 30 * time.Second}
    response, err := client.Do(httpRequest)
    if err != nil {
        panic(err)
    }
    defer response.Body.Close()
    responseBody, err := io.ReadAll(response.Body)
    if err != nil {
        panic(err)
    }
    if response.StatusCode >= http.StatusBadRequest {
        panic(fmt.Sprintf("HCTI request failed (%d): %s", response.StatusCode, responseBody))
    }

    var result struct {
        URL string `json:"url"`
    }
    if err := json.Unmarshal(responseBody, &result); err != nil {
        panic(err)
    }
    fmt.Println(result.URL)
}

```

## When to use JPEG

JPEG is a practical choice for photographic and content-heavy webpages where broad compatibility and smaller files matter.

- **Smaller photo-heavy captures**: Lossy compression keeps screenshots compact when pages contain photography, gradients, or detailed backgrounds.
- **Broad compatibility**: JPEG works across browsers, email clients, social platforms, document tools, and long-running application workflows.
- **Easy to distribute**: Use a familiar image format for previews, downloads, attachments, reports, and automated publishing.

## API request

Send an authenticated `POST` request to `https://hcti.io/v1/image`. Include `url`, `format`, and any viewport, selector, timing, or browser options required for the capture.

```json
{
  "url": "https://example.com",
  "format": "jpeg",
  "viewport_width": 1200,
  "viewport_height": 630
}
```

## Request workflow

1. **Send the webpage URL** — Submit a public URL with format set to jpeg and any viewport, selector, or browser settings.
2. **Chromium loads the page** — The API runs the webpage, styles, fonts, images, and JavaScript in a managed browser environment.
3. **Use the .jpeg URL** — Embed the hosted result, download the file, or save it in your own storage and application records.

## Capture controls and output handling

- Authenticate from trusted server-side code. Do not expose an API key in browser JavaScript, logs, or agent-visible output.
- Use `full_screen`, `selector`, viewport dimensions, timing, and browser options to capture the required page state.
- Treat the returned URL as the generated `jpeg` resource. Download it, embed it, or copy it to configured storage as required.

## Use through MCP

An MCP-compatible agent can connect to `https://mcp.hcti.io` with OAuth and use the connected HTML/CSS to Image account instead of handling an API key directly.

Ask the MCP tool to capture the supplied URL as JPEG, or specify `format: jpeg` explicitly in the request.

- [Read the MCP integration documentation](https://docs.htmlcsstoimage.com/integrations/mcp/)

## Related conversions

- [HTML to JPEG](https://htmlcsstoimage.com/features/html-to-jpeg/golang.md): Render supplied HTML and CSS as JPEG instead of capturing a public webpage.
- [URL to PNG](https://htmlcsstoimage.com/features/url-to-png/golang.md): PNG preserves sharp text, interface details, and transparency, making it a reliable format for webpage archives and UI captures.
- [URL to WebP](https://htmlcsstoimage.com/features/url-to-webp/golang.md): WebP combines modern compression with strong visual quality, making it a good fit for webpage screenshots delivered on the web.
- [URL to PDF](https://htmlcsstoimage.com/features/url-to-pdf.md): Generate paginated documents from public webpages with page sizing, margins, backgrounds, and print styles.

## Reference links

- [URL screenshot API documentation](https://docs.htmlcsstoimage.com/getting-started/url-to-image/)
- [MCP integration documentation](https://docs.htmlcsstoimage.com/integrations/mcp/)
- [Interactive URL to JPEG page](https://htmlcsstoimage.com/features/url-to-jpeg/golang)
- [Plans and current limits](https://htmlcsstoimage.com/pricing.md)
