f(G) (or im(f) as you call it) is a subgroup of H, so |f(G)| divides |H|.

let K = ker(f), then |f(G)| = |G|/|K| (since f(G) is isomorphic to G/ker(f), by the FIT).

thus |K||f(G)| = |G|, so |f(G)| divides |G|. this implies |f(G)| divides gcd(|G|,|H|).