If $f:\mathbb R^2 \to \mathbb R$ continuous on straight lines and $f(\text{compact})= \text{compact}$, then $f$ continuous?

Yes. Assume otherwise. WLOG, $f(0)=0$ is discontinuous and find $x_n\to 0$ such that $f(x_n)$ does not converge to zero. If $f(x_n)$ is unbounded, then the image of the compact set $\{0\}\cup \{x_n\}$ is not compact. So $f(x_n)$ is bounded. Choose a subsequence $x_n'$ such that $f(x_n')$ converges to $c\neq 0$. If $c\neq f(x_n')$ for each $n$, we are done, because $\{0\}\cup \{x_n'\}$ is compact and the image is not.

Now for each $n$ where $c=f(x_n')$, we use the continuity on the line $\{tx_n'\,| t\in R\}$ and find a number $x_n'' = t_n x_n'$ for some $0< t_n < 1$ so that $f(x_n'')=c(1 - \frac{1}{n})$. If $f(x_n')\neq c$, we leave $x_n'':=x_n'$. So then $f(x_n'')$ still converges to $c$, $x_n''$ still converges to $0$, but the image of $\{0\}\cup \{x_n''\}$ is not compact.


Hint: Fix $x\in\mathbb R^2$ and $\varepsilon>0$. For every ray $\ell_\varphi=\{x+(t\cos \varphi, t\sin\varphi) \colon t\in[0,\infty)\}$ let $g(\varphi)=\inf\{t \colon |f(x)-f((t\cos \varphi, t\sin\varphi))|>\varepsilon\}$. Suppose that there exists no $\delta>0$ with $d(x,y)<\delta \implies |f(x)-f(y)|<\varepsilon$. Choose a sequence $\varphi_n$ such that $\lim_{n\to\infty} g(\varphi_n)=0$. For all $n$ choose $t_n$ such that $g(\varphi_n)<t_n<g(\varphi_n)+\frac 1n$ and $|f(x)-f(x_n)|<\varepsilon+\frac 1n$ where $x_n=x+(t_n\cos\varphi_n,t_n\sin\varphi_n)$ (this can be done by first condition). Consider then the set $K=\{x\} \cup \{x_n \colon n=1,2,\ldots\}$ and obtain a contradiction with second condition.