I recently learned that if $f: G \to Z(G)$ is a homomorphism of $G$ to its center, then $g:G \to G$ defined as $g(x)=f(x)x$ is an endomorphism of $G$.
I am having trouble thinking of examples of a (finite) group with a non-trivial homomorphism from itself to its center. This excludes trivial centers and abelian groups. Can someone give me at least two examples?
EDIT: It occurs to me that if $G=H \times A$ for some group $H$ with non-trivial center and abelian group $A$, then the map $f:(x,y) = y$ is a homomorphism. In essence, the automorphism $g$ is then $g(x,y) = (x,y^2)$. An example where $G$ cannot be decomposed as such would be appreciated.
EDIT: I think I have some confusion about the properties of $f$ in order that $g$ must be an automorphism. That is, I am unsure if the image of $f$ must be the entire center or not.
For any finite field $F$ and any $n$, you can consider $G:=\operatorname{GL}_n$, whose center is $F^\times I$ where $I$ is the identity matrix. Now, take the determinant as your homomorphism.