We provide a general framework for deriving Hamiltonian electromagnetic gyrofluid models from a Hamiltonian system of gyrokinetic equations. The presented procedure permits to derive gyrofluid models for an arbitrary number of moments with respect to the velocity coordinate parallel to an equilibrium magnetic field. The resulting gyrofluid models account, in particular, for finite Larmor radius effects, equilibrium temperature anisotropies and fluctuations of the magnetic field in the direction parallel to the equilibrium magnetic field, thus generalizing Hamiltonian gyrofluid models previously presented in the literature. The Hamiltonian reduction procedure leading from the parent gyrokinetic model to the gyrofluid models is formulated in two stages. In the first step, after having shown that the parent gyrokinetic system indeed posseses a Hamiltonian structure, a Hamiltonian system is derived, by means of a Poisson sub-algebra argument, which describes the evolution of the perturbation of the gyrocenter distribution function, averaged with respect to the magnetic moment coordinate. The second stage brings from the latter model to the gyrofluid models by means of a closure relation, applicable at an arbitrary order in the moment hierarchy, which guarantees the preservation of a Hamiltonian structure. Casimir invariants of the noncanonical Poisson brackets of the gyrofluid models are provided. It is also shown how, in the two-dimensional limit, the gyrofluid model equations can be cast in the form of advection equations for Lagrangian invariants transported by generalized incompressible velocity fields, thus extending results obtained for previous Hamiltonian gyrofluid and drift-fluid models. The Hamiltonian reduction procedure is applied to derive a five-field gyrofluid model evolving the first two moments for the electron species and the first three moments for the ion species. The Casimir invariants and the Lagrangian advection formulation are provided explicitly for the five-field model. Remarks concerning possible variants of the procedure are discussed. As an example, it is shown how, by means of a variant of the procedure, it is possible to derive an isothermal two-field model for kinetic Alfvén waves including equilibrium electron temperature anisotropy effects.