Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

PHP cannot convert HTML directly to JPEG with imagejpeg(): that function encodes an existing image, not a web page. First render HTML and CSS into a PDF or browser image; then encode or rasterize the result as JPEG. For a PHP-based workflow, Dompdf can render HTML to PDF and Imagick can rasterize the PDF and write JPEG output. If you need JavaScript execution or closer parity with a modern browser, use a real browser renderer or a hosted screenshot API instead.

Choose the rendering path before writing conversion code

The conversion has two distinct jobs: a layout engine turns markup, styles, fonts and assets into pixels; an image encoder stores those pixels as JPEG. PHP’s GD function imagejpeg() performs only the second job. It accepts a GD image resource or object and writes it to a file or the response, with a quality value from 0 to 100. PHP manual: imagejpeg()

Approach What it renders Best fit Important limitation
Dompdf, then Imagick HTML/CSS to PDF, then PDF page to JPEG PHP applications where PDF output is acceptable as an intermediate Dompdf is mostly CSS 2.1 compliant, not a full modern browser, and does not execute page JavaScript.
GD imagejpeg() An already-created GD bitmap to JPEG Encoding or streaming image pixels you already have It does not parse or lay out HTML.
Browser renderer or hosted screenshot API A page rendered by a browser engine JavaScript-heavy pages or browser-like CSS rendering Confirm supported formats, asset access, security model, and service terms for your use case.

Dompdf describes itself as a mostly CSS 2.1-compliant HTML layout and rendering engine written in PHP, and its documented output is PDF. It supports external stylesheets, UTF-8 and common image formats, along with selected CSS3 features; malformed HTML and unsupported styling can affect the result. Dompdf documentation and Dompdf features.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Render HTML to JPEG with Dompdf and Imagick

This workflow renders one HTML document as a PDF, opens the first PDF page with Imagick, then encodes it as JPEG. Install Dompdf and Imagick in the PHP environment, and verify that the ImageMagick build permits PDF reading through its installed delegate and security policy. PDF reading is not enabled in every deployment.

#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Prerequisites and setup

  • Install Dompdf using its project installation instructions, and ensure the PHP DOM and MBString extensions required by Dompdf are available.
  • Install the Imagick PHP extension and an ImageMagick build with PDF input enabled. Some builds rely on a PDF delegate; policy restrictions may deny access even when the extension is installed.
  • Use well-formed HTML. Dompdf documents compatibility limits and recommends validating input or using its HTML5 parser for HTML5 markup.
  • Make fonts and images available to the renderer, and decide whether remote assets are permitted. Treat untrusted HTML and externally supplied URLs as security-sensitive inputs.

Complete example

The example assumes Dompdf is installed through Composer and that your ImageMagick configuration allows reading the generated PDF. It saves a one-page HTML document to page.jpg. Adjust the document, dimensions and quality for your application.

<?php
require __DIR__ . '/vendor/autoload.php';

use DompdfDompdf;
use DompdfOptions;

$html = '<!doctype html>
<html>
<head>
  <meta charset="UTF-8">
  <style>
    @page { size: 1200px 800px; margin: 0; }
    html, body { margin: 0; padding: 0; }
    body { font-family: sans-serif; color: #222; }
    .canvas { box-sizing: border-box; width: 1200px; height: 800px; padding: 48px; }
  </style>
</head>
<body>
  <main class="canvas">
    <h1>A page rendered by PHP</h1>
    <p>Dompdf lays out this HTML as a PDF page before rasterization.</p>
  </main>
</body>
</html>';

$options = new Options();
// Keep remote loading disabled unless this document needs trusted remote assets.
$options->set('isRemoteEnabled', false);
$dompdf = new Dompdf($options);
$dompdf->loadHtml($html, 'UTF-8');
$dompdf->setPaper([0, 0, 1200, 800]);
$dompdf->render();

$pdfPath = __DIR__ . '/page.pdf';
file_put_contents($pdfPath, $dompdf->output());

$imagick = new Imagick();
// Density controls rasterization resolution; set it before reading the PDF.
$imagick->setResolution(144, 144);
$imagick->readImage($pdfPath . '[0]');
$imagick->setImageFormat('jpeg');
$imagick->setImageCompression(Imagick::COMPRESSION_JPEG);
$imagick->setImageCompressionQuality(82);
$imagick->writeImage(__DIR__ . '/page.jpg');
$imagick->clear();
$imagick->destroy();
?>

This is an implementation pattern, not a guarantee that every PHP/ImageMagick installation can read PDFs. Check the deployment’s PDF delegate and security policy before relying on the rasterization step. Imagick provides setImageFormat(); ImageMagick documents JPEG support and conversion operations. PHP manual: Imagick::setImageFormat(), ImageMagick formats, and ImageMagick conversion.

Choosing page size and output dimensions

PDF page dimensions and rasterization density jointly determine the pixel dimensions. For a fixed physical page, increasing density increases the number of pixels and usually the file size. If the result must have exact pixel dimensions, define the layout dimensions deliberately and inspect the actual raster output in the target environment rather than assuming the PDF’s nominal size maps one-to-one to pixels.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

For multi-page HTML, the sample deliberately reads only page zero with [0]. To produce one JPEG per PDF page, iterate over the pages or read the PDF as an image sequence and write each page separately. Decide what the consumer expects: a single first-page preview, a set of page files, or a different format for multi-page content.

Use GD when you already have image pixels

If another PHP component has produced a GD image, imagejpeg() can write it to disk or stream it. The quality parameter ranges from 0 to 100; the documented default is -1, which uses the default IJG quality (about 75). Set quality explicitly when predictable output matters. PHP manual: imagejpeg()

<?php
// $im must already be a valid GD image; this does not render HTML.
$im = imagecreatetruecolor(800, 600);
$background = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $background);

$path = __DIR__ . '/bitmap.jpg';
if (!imagejpeg($im, $path, 82)) {
    throw new RuntimeException('Could not write JPEG output.');
}
imagedestroy($im);
?>

JPEG has no transparency. If your source pixels include transparent areas, choose and fill a background before encoding so the final appearance is intentional. Lower JPEG quality usually reduces file size while introducing more visible compression artifacts; inspect small text, thin lines and gradients at the sizes readers will actually view.

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

When a browser-based renderer is the better fit

Dompdf is useful when a PHP-based layout engine and PDF intermediary fit the job. It is not a substitute for executing a modern browser: if the page depends on JavaScript, browser-only CSS, client-side data loading or exact browser font/layout behavior, investigate a real browser renderer or hosted rendering service. The sources cited here do not establish a PHP-native browser engine or the feature set of any particular alternative, so verify the chosen renderer’s JPEG support, asset-loading rules, security controls and licensing before deployment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For server-side rendering of untrusted or user-provided URLs, include the renderer in your security design. Decide which network destinations it may access, whether remote resources are allowed, how long a render may run, and how large a document may be. Keep PDF and image processing libraries patched and apply appropriate resource limits; do not treat a URL supplied by a user as safe just because it is being rendered rather than displayed.

Or skip the browser setup

If you need a browser-rendered screenshot rather than a PHP-local PDF pipeline, ScreenshotNeo is a website screenshot API and MCP server. Its one-call endpoint can return a JPEG; the API also supports PNG, WebP and PDF. This cURL example saves the capture as a JPEG using the documented format parameter:

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -d format=jpeg -o shot.jpg

See the ScreenshotNeo API documentation for authentication and request options. Cookie banners are accepted and removed before capture, along with known newsletter popups and chat widgets; these steps can be turned off. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing status. An MCP server provides take_screenshot, get_page_info and capture_pdf tools for AI agents. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to try up to 1,000 screenshots a month with no card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common failures

  • The output is not a screenshot of the page. imagejpeg() only encodes an existing bitmap. Render HTML first with a layout engine or browser, then encode its output.
  • Imagick cannot read the PDF. The deployed ImageMagick build may lack an enabled PDF delegate, or its security policy may block PDF input. Check the installed build and policy; do not assume that installing the PHP extension enables PDF rasterization.
  • Text, CSS or layout differs from a browser. Dompdf is mostly CSS 2.1 compliant and has HTML/CSS compatibility limits. Simplify unsupported styling or use a browser renderer when browser fidelity or JavaScript execution is required.
  • Images, fonts or stylesheets are missing. Check that asset paths resolve in the renderer’s environment and that remote loading is configured only when needed. Confirm permissions and network access for the PHP process.
  • Malformed markup produces unexpected output. Validate and clean the HTML; use Dompdf’s HTML5 parser where appropriate.
  • JPEG dimensions are wrong or text looks soft. Review PDF page size and Imagick resolution together. Inspect output dimensions and test a higher rasterization density where more pixels are needed.
  • Transparent regions turn dark or unexpected colors. JPEG does not support transparency. Composite onto a chosen background before saving.
  • The request runs out of memory or takes too long. Large pages, high rasterization density and multiple PDF pages increase processing demands. Render only the needed page, lower dimensions where acceptable, and measure memory and elapsed time on the target deployment.
  • The JPEG looks blocky or is too large. Adjust the JPEG quality setting and compare legibility against file size for the actual content; do not optimize by quality number alone.

Performance, reliability and cost decisions

No published performance figures are established for these workflows. Measure render time, memory use and output size with representative HTML, fonts, images and page counts in the deployment environment. Local rendering avoids a remote screenshot request but requires maintaining PHP extensions, ImageMagick delegates and security policy. A browser-based service shifts rendering infrastructure outside the PHP application, but introduces an external dependency and should be evaluated for its supported output, latency, reliability and data-handling terms.

For cost, account for the server resources of local PDF generation and rasterization, including peak memory for large pages. For a hosted API, compare its billing rules and quotas against expected successful captures and verify what happens on failed pages, cache hits and request timeouts. Do not infer throughput or output fidelity from pricing alone.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

Frequently Asked Questions

Can PHP convert HTML directly to JPEG with GD?

No. GD’s imagejpeg() encodes an existing GD bitmap; it does not render HTML or CSS.

Can Dompdf produce a JPEG file?

Dompdf’s documented output is PDF. To create JPEG output, rasterize the PDF with a compatible tool such as Imagick/ImageMagick.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does Dompdf run JavaScript in the HTML page?

The cited Dompdf documentation describes HTML/CSS layout, not browser JavaScript execution. Use a browser renderer if the page depends on JavaScript.

Why might PDF rasterization work locally but fail in production?

ImageMagick’s PDF-reading delegate or security policy can differ between environments. Verify PDF input support on the deployed build.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.