This paper presents an optimization method to reduce blocking artifacts in JPEG images by utilizing the image gradient information. A closed-form solution is derived for the optimization method. To address the computational feasibility aspect of the large matrices involved in the closed-form solution, a sliding window approach is devised. The performance of the developed method is compared with several blocking artifacts reduction methods in the literature and also with the deblocking filter deployed in high efficiency video coding by examining the three measures of peak signal-to-noise ratio, generalized block-edge impairment metric (), and structural similarity. The comparison results indicate the effectiveness of the introduced method in particular for low bit-rate JPEG images.