This paper describes an iterative method of per-pixel energy calibration of hybrid pixel detectors with GaAs:Cr sensor and Timepix readout chip. A convolution of precisely measured spectra of characteristic X-rays of different metals with the resolution and the efficiency of the pixel detector is used for the calibration. The energy resolution of the detector is also measured during the calibration. The use of per-pixel calibration allows to achieve a good energy resolution of the Timepix detector with GaAs:Cr sensor: 8% and 13% at 60 keV and 20 keV, respectively.