Suppose $X$ is a topological space. We have the following criterion for compactness:
Theorem. $X$ is compact if and only if for every space $Y$, the second projection $\pi_2: X\times Y \to Y$ is a closed map.
This property is known as being universally closed, and also plays an important role in algebraic geometry (in the definition of a proper morphism). The proof of the result above can be found on this MSE thread.
My question is whether we can strengthen this result by only asking that the graphs of continuous functions have closed image in $Y$. From now on, we will consider only Hausdorff topological spaces.
Question. Is it true that a Hausdorff space $X$ is compact if and only if for every continuous map $f: X\to Y$ with $Y$ Hausdorff has a closed image $f(X)$ in $Y$.
More context for the question: let $X$ and $Y$ be any two Hausdorff spaces. For any continuous function $f: X\to Y$ we can consider its graph $\Gamma(f) = \{(x, y)\in X\times Y: y=f(x)\}$. Note that $\Gamma(f)\subset X\times Y$ is a closed subset of $Y$ (see this MSE thread for proof). If $X$ were compact, then we know that the image of $\Gamma(f)$ under the second projection map $X\times Y\to Y$ would be closed. Note that the image of $\Gamma(f)$ is precisely the image $f(X)=\{f(x)\in Y: x\in X\}$, and so $f(X)$ would be closed in $Y$. This shows that the forward implication is true (one can show this implication in a more direct away). It makes sense to ask whether the converse also holds.