Replace each pixel with corresponding statistic from the neighborhood of the specified width and height.
function statisticImage($image_path, $statisticType, $width, $height, $channel)
{
    $imagick = new \Imagick(realpath($image_path));

    $imagick->statisticImage(
        $statisticType,
        $width,
        $height,
        $channel
    );

    header("Content-Type: image/jpeg");
    echo $imagick->getImageBlob();
}