It is well-known that continuous image of any compact set is compact, and that continuous image of any connected set is connected. How far is the converse of the above statements true?

More precisely: Let $X$ be a topological space. Suppose there is a map $f$ from $X$ into itself which takes compact sets to compact sets and connected sets to connected sets. Do these conditions imply that $f$ is continuous?

If not in general, at least when $X$ is a metric space? or, when $f$ is a bijection? or both? or under any other additional conditions?

My apologies if my question in boringly elementary.

Thanks in advance!