Algorithm for image of a free group homomorphism

Let $G$ and $H$ be finitely generated free groups, and let $f:G\to H$ be a homomorphism specified by giving the images of the generators of $G$.

Is there an algorithm which takes such an $f$ and a word $w\in H$ and tells if $w \in f(G)$?

Is there such an algorithm in the special case where $G=H$?

Thanks-

-
See gap-system.org/Manuals/pkg/fga/doc/manual.pdf section 2.3 for a GAP implementation. –  Guntram Jan 22 '12 at 17:14