Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchUse the browser’s canvas API: wait for the <img> to load, draw it at its intrinsic size, then encode the canvas as JPEG. For a downloadable file, canvas.toBlob('image/jpeg', quality) is the practical choice; use toDataURL() when an API specifically needs a data URL. A cross-origin image must grant CORS access before its pixels can be exported.
The browser-native conversion workflow
An HTML image is normally a resource referenced by an <img> element, not a JPG file you can rename. Canvas provides the bridge between the rendered pixels and a JPEG encoder.
- Wait until the image has loaded successfully.
- Create a canvas whose dimensions match
img.naturalWidthandimg.naturalHeight. - Draw the image with
ctx.drawImage(img, 0, 0). - Encode the canvas as JPEG with a quality value from
0to1. - Download the resulting Blob or pass a data URL to another API.
Complete JavaScript download example
This version converts an existing image element and downloads converted.jpg. It uses the asynchronous Blob API, which avoids building the entire encoded image as one large JavaScript string.
function imageToJpg(img, quality = 0.92) {
if (!img.complete || img.naturalWidth === 0) {
return Promise.reject(new Error('Image has not loaded successfully'));
}
const canvas = document.createElement('canvas');
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;
const ctx = canvas.getContext('2d');
if (!ctx) {
return Promise.reject(new Error('Canvas 2D context is unavailable'));
}
ctx.drawImage(img, 0, 0);
return new Promise((resolve, reject) => {
canvas.toBlob(blob => {
if (blob) resolve(blob);
else reject(new Error('JPEG encoding was not supported'));
}, 'image/jpeg', quality);
});
}
async function downloadJpg(img, filename = 'converted.jpg') {
const blob = await imageToJpg(img);
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = filename;
document.body.appendChild(link);
link.click();
link.remove();
URL.revokeObjectURL(url);
}
const img = document.querySelector('#source-image');
img.addEventListener('load', () => {
downloadJpg(img).catch(console.error);
}, { once: true });
if (img.complete && img.naturalWidth > 0) {
downloadJpg(img).catch(console.error);
}
The intrinsic dimensions preserve the source resolution. If you intentionally want a smaller or larger result, set the canvas dimensions to your target width and height and draw with the destination rectangle:
Recommended Free Tools
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
const targetWidth = 1200;
const targetHeight = Math.round(img.naturalHeight * targetWidth / img.naturalWidth);
canvas.width = targetWidth;
canvas.height = targetHeight;
ctx.drawImage(img, 0, 0, targetWidth, targetHeight);
Using toDataURL() instead
For a small image or an API that explicitly accepts a data URL, encode the canvas synchronously:
const dataUrl = canvas.toDataURL('image/jpeg', 0.92);
toDataURL() returns a string beginning with data:image/jpeg;base64, when JPEG is supported. It keeps the complete encoded image in memory as a string, so toBlob() is generally better for large images and downloads. If a requested format is unsupported, browsers can fall back to PNG; check the returned prefix when the format matters.
Quality, dimensions, and transparency
Choose a quality value deliberately
The quality argument is between 0 and 1. Higher values usually preserve more detail and create larger files; lower values reduce size while increasing blockiness, ringing, or blurred fine text. A value around 0.9 is a reasonable starting point, but compare the actual file size and visible artifacts for your use case.
Preserve or resize pixels
Use naturalWidth and naturalHeight for a full-resolution conversion. CSS width and height describe layout and may not equal the downloaded pixel dimensions. Explicit canvas dimensions are appropriate when the conversion also promises resizing.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Handle transparent sources
JPEG has no alpha channel. Transparent pixels therefore cannot remain transparent. Paint a background before drawing the image:
ctx.fillStyle = '#ffffff';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(img, 0, 0);
Choose a background that matches the intended design; otherwise transparent areas may become an unexpected black or browser-dependent color.
Cross-origin images and the tainted-canvas error
Same-origin images are normally exportable. An image hosted on another origin must opt in to pixel access with CORS response headers. Set crossOrigin before assigning src:
const img = new Image();
img.crossOrigin = 'anonymous';
img.onload = () => {
downloadJpg(img).catch(console.error);
};
img.onerror = () => console.error('The image failed to load');
img.src = 'https://cdn.example.com/photo.png';
The image server must return an appropriate Access-Control-Allow-Origin header. JavaScript cannot override a server that withholds permission. If foreign pixels were drawn without valid CORS permission, the canvas becomes tainted and toBlob(), toDataURL(), or pixel reads throw a SecurityError.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
When you do not control the image host
- Ask the provider to enable CORS for your site.
- Fetch the image through a server-side proxy that you operate and are authorized to use, then serve it with suitable CORS headers.
- Do not treat an arbitrary public CORS proxy as guaranteed, private, reliable, or appropriate for confidential images.
Converting an image selected by the user
A file input avoids remote-origin restrictions because the selected file is local to the page. Create an object URL, load it, convert it, and revoke the URL after the image finishes loading:
const input = document.querySelector('#file');
input.addEventListener('change', async () => {
const file = input.files[0];
if (!file) return;
const img = new Image();
const objectUrl = URL.createObjectURL(file);
try {
img.src = objectUrl;
await new Promise((resolve, reject) => {
img.onload = resolve;
img.onerror = () => reject(new Error('Selected file is not a readable image'));
});
const jpg = await imageToJpg(img, 0.92);
const downloadUrl = URL.createObjectURL(jpg);
const link = document.createElement('a');
link.href = downloadUrl;
link.download = file.name.replace(/.[^.]+$/, '') + '.jpg';
link.click();
URL.revokeObjectURL(downloadUrl);
} finally {
URL.revokeObjectURL(objectUrl);
}
});
This conversion happens in the browser. The original file is not uploaded unless your own code sends it elsewhere.
Performance and reliability considerations
- Prefer Blob output: it avoids a large base64 string and works naturally with object URLs, downloads, and form uploads.
- Release object URLs: call
URL.revokeObjectURL()after a download or preview is no longer needed. - Expect memory use proportional to pixels: very large images require a large canvas and encoded buffer. Resize in stages or reject dimensions that exceed your application’s safe limit.
- Wait for the real load event: cached images may already be complete, while a broken image can also have completed loading; check
naturalWidth > 0. - Do not assume every browser encoder behaves identically: test the formats and quality levels your supported browsers must handle.
Troubleshooting
“The canvas has been tainted by cross-origin data”
The image server did not grant CORS access, or crossOrigin was set after src. Set it first and configure the server, or move the authorized fetch to your backend.
The output is blank or only partly drawn
Conversion began before the image loaded, or the source failed. Attach an onload handler, verify naturalWidth, and inspect the network request for redirects, authentication failures, and content-type errors.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
The JPEG has black or unexpected transparent areas
JPEG does not support alpha. Fill the canvas with an intentional background before drawing.
The file is much larger than expected
Lower the quality value, resize to the required pixel dimensions, or use a format that better suits the content when JPEG is not mandatory. Photographs generally compress better than screenshots containing sharp text.
toBlob() returns null
The requested encoder was unavailable or the canvas could not be encoded. Confirm that the canvas is valid and that the browser supports JPEG output; reject the conversion rather than silently delivering another format.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If your real goal is to capture an HTML page or image as a clean file rather than build a client-side converter, ScreenshotNeo provides a website screenshot API. One GET request returns PNG, JPEG, WebP, or PDF. It accepts consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers identify the page verdict and billing status.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
See the parameter details in the ScreenshotNeo documentation. A JPEG request with cURL is:
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
The same request in Python:
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
And in Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
ScreenshotNeo also offers an MCP server with take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. Features include full-page and element capture, device presets, retina scale, custom CSS and JavaScript, waits, request blocking, headers and cookies, geolocation, signed links, asynchronous webhooks, bulk capture, caching, and HTML/CSS-to-image. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.
FAQ
Can I convert an HTML <img> directly by changing its extension?
No. The extension does not change the encoded bytes. Draw the image into a canvas or use an authorized server-side conversion.
Does converting to JPEG improve image quality?
No. JPEG is usually lossy. It can reduce file size, but it cannot restore detail already missing from the source.
Free tools Windows power users keep installed
One-click scans. No signup required.
Why does the browser show a different size than naturalWidth?
CSS dimensions control layout, while naturalWidth reports the image’s intrinsic pixel dimensions. Canvas conversion uses whichever dimensions you assign.
Frequently Asked Questions
Can an SVG in an HTML image be converted to JPG?
Yes, if it loads successfully and its referenced resources are permitted by the browser’s origin rules; draw the loaded image onto canvas, supply a background for transparent regions, and export as JPEG.
Can I preserve EXIF metadata during browser conversion?
Canvas encoding creates a new JPEG and does not provide a general way to preserve the source file’s metadata. Use a metadata-aware server workflow when that information is required.
Quick Recap
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.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errors

