[proofplan]
Choose a kernel of $f$ and then quotient $A$ by this kernel to obtain the coimage map $p:A \to \operatorname{coim} f$. Since $f$ kills its kernel, the universal property of the cokernel $p$ produces a unique induced morphism $g:\operatorname{coim} f \to B$. Then choose a cokernel of $f$ and take its kernel $i:\operatorname{im} f \to B$; because $qg$ vanishes after precomposition with the epimorphism $p$, it vanishes, so $g$ factors uniquely through $i$. The resulting factor through the image is the desired canonical morphism $\bar f$.
[/proofplan]
[step:Factor $f$ through the cokernel of its kernel]
Let
\begin{align*}
k:K \to A
\end{align*}
be the chosen kernel of $f:A \to B$, and let
\begin{align*}
p:A \to C
\end{align*}
denote its chosen cokernel, where $C:=\operatorname{coim} f$.
Because $k$ is a kernel of $f$, we have
\begin{align*}
fk = 0_{K,B}.
\end{align*}
By the universal property of the cokernel $p:A \to C$ of $k$, applied to the morphism $f:A \to B$, there exists a unique morphism
\begin{align*}
g:C \to B
\end{align*}
such that
\begin{align*}
gp = f.
\end{align*}
[/step]
[step:Record that the coimage projection is an epimorphism]
The morphism $p:A \to C$ is an epimorphism. Indeed, let $u,v:C \to X$ be morphisms in $\mathcal A$ such that
\begin{align*}
up = vp.
\end{align*}
Set $h:=up=vp:A \to X$. Since $pk=0_{K,C}$, we have
\begin{align*}
hk = upk = u0_{K,C} = 0_{K,X}.
\end{align*}
Thus $h$ annihilates $k$. The universal property of the cokernel $p$ says that there is a unique morphism $C \to X$ whose composite with $p$ is $h$. Both $u$ and $v$ have this property, so $u=v$. Hence $p$ is an epimorphism.
[/step]
[step:Show that the induced map lands in the kernel of the cokernel]
Let
\begin{align*}
q:B \to Q
\end{align*}
be the chosen cokernel of $f$, and let
\begin{align*}
i:I \to B
\end{align*}
be the chosen kernel of $q$, where $I:=\operatorname{im} f$.
We prove that $g:C \to B$ is killed by $q$. Since $gp=f$, we compute
\begin{align*}
(qg)p = q(gp) = qf = 0_{A,Q},
\end{align*}
because $q$ is a cokernel of $f$. Since $p$ is an epimorphism, cancellation on the right gives
\begin{align*}
qg = 0_{C,Q}.
\end{align*}
[/step]
[step:Factor through the image and obtain the canonical comparison morphism]
Since $i:I \to B$ is the kernel of $q:B \to Q$ and $qg=0_{C,Q}$, the universal property of the kernel $i$ gives a unique morphism
\begin{align*}
\bar f:C \to I
\end{align*}
such that
\begin{align*}
i\bar f = g.
\end{align*}
Substituting $g p=f$ gives
\begin{align*}
i\bar f p = gp = f.
\end{align*}
Using $C=\operatorname{coim} f$ and $I=\operatorname{im} f$, this is precisely the factorisation
\begin{align*}
A \xrightarrow{p} \operatorname{coim} f \xrightarrow{\bar f} \operatorname{im} f \xrightarrow{i} B.
\end{align*}
[/step]
[step:Prove uniqueness of the middle morphism]
Let
\begin{align*}
\theta:\operatorname{coim} f \to \operatorname{im} f
\end{align*}
be any morphism satisfying
\begin{align*}
i\theta p = f.
\end{align*}
Since $gp=f$, we have
\begin{align*}
i\theta p = gp = i\bar f p.
\end{align*}
The morphism $i$ is a monomorphism because every kernel is a monomorphism, so
\begin{align*}
\theta p = \bar f p.
\end{align*}
The morphism $p$ is an epimorphism by the previous step, so
\begin{align*}
\theta = \bar f.
\end{align*}
Therefore the morphism $\bar f:\operatorname{coim} f \to \operatorname{im} f$ with $f=i\bar f p$ is unique, completing the proof.
[/step]