diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
index 0d410a4b23..e19173c06e 100644
--- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
+++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
@@ -691,6 +691,20 @@ NonnullRefPtr CanvasRenderingContext2D::create_conic_gradient(do
return CanvasGradient::create_conic(start_angle, x, y);
}
+// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-transform
+void CanvasRenderingContext2D::transform(double a, double b, double c, double d, double e, double f)
+{
+ // 1. If any of the arguments are infinite or NaN, then return.
+ if (!isfinite(a) || !isfinite(b) || !isfinite(c) || !isfinite(d) || !isfinite(e) || !isfinite(f))
+ return;
+
+ // 2. Replace the current transformation matrix with the result of multiplying the current transformation matrix with the matrix described by:
+ // a c e
+ // b d f
+ // 0 0 1
+ m_drawing_state.transform.multiply({ static_cast(a), static_cast(b), static_cast(c), static_cast(d), static_cast(e), static_cast(f) });
+}
+
// https://html.spec.whatwg.org/multipage/canvas.html#check-the-usability-of-the-image-argument
DOM::ExceptionOr check_usability_of_image(CanvasImageSource const& image)
{
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
index f7465670b0..a965ec9121 100644
--- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
+++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
@@ -98,6 +98,8 @@ public:
NonnullRefPtr create_linear_gradient(double x0, double y0, double x1, double y1);
NonnullRefPtr create_conic_gradient(double start_angle, double x, double y);
+ void transform(double a, double b, double c, double d, double e, double f);
+
private:
explicit CanvasRenderingContext2D(HTMLCanvasElement&);
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl
index a16ffbf4f8..6f64ad7dd2 100644
--- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl
+++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl
@@ -55,4 +55,7 @@ interface CanvasRenderingContext2D {
CanvasGradient createLinearGradient(double x0, double y0, double x1, double y1);
CanvasGradient createConicGradient(double startAngle, double x, double y);
+ // FIXME: All these `double`s should be `unrestricted double`
+ undefined transform(double a, double b, double c, double d, double e, double f);
+
};