1. An image forming apparatus comprising: an image bearer; an image forming device to form a toner image on the image bearer; a transfer device to transfer the toner image from the image bearer to a recording medium; a line sensor as an image density sensor to detect image density of the toner image on the image bearer, the image density sensor being disposed so as to be shorter in a rotational direction of the image bearer than in a width direction of the image bearer perpendicular to the rotational direction of the image bearer; and a controller operatively connected to the image density sensor, to form a shading pattern image including a plurality of patches subject to detection on an outer circumferential surface of the image bearer with the image forming device, the shading pattern image being shorter in the rotational direction of the image bearer than in the width direction of the image bearer, and to detect image density of the plurality of patches of the shading pattern image with the image density sensor, so as to control image density.