CodexBloom - Programming Q&A Platform

HTML `<canvas>` not rendering correctly in Safari with `imageSmoothingEnabled` set to false

👀 Views: 140 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-12
html canvas safari JavaScript

I've been struggling with this for a few days now and could really use some help. I'm stuck on something that should probably be simple. I'm working with an scenario where my HTML `<canvas>` element is not rendering images as expected in Safari, specifically when I set the `imageSmoothingEnabled` property to `false`. The canvas appears pixelated, and the images are not being displayed properly. This scenario does not occur in Chrome or Firefox, where the images render clearly and without any smoothing. Here's the code snippet I'm using: ```javascript const canvas = document.getElementById('myCanvas'); const ctx = canvas.getContext('2d'); const image = new Image(); image.src = 'path/to/image.png'; image.onload = () => { ctx.imageSmoothingEnabled = false; ctx.drawImage(image, 0, 0); }; ``` I've also tried adjusting the canvas size and the image size to match, but the question continues. The pixelation seems to be more pronounced with images that have transparency. I checked Safari's console, and there are no behavior messages or warnings related to this. Has anyone else encountered similar behavior in Safari, and are there any suggested workarounds or fixes to ensure consistent rendering across browsers? For context: I'm using Javascript on Windows. How would you solve this? I'm working on a service that needs to handle this.