分页符不能用于fpdf中的图像

I am using FPDF library to create PDF in my php application using database content.The data contains both images and data.I have an array of images for printing. My issue is the page break not working with images.When it reaches bottom of page, does not create new page instead it writes first two or three images to the first page others get cut off.The page breaks works when text is write to pdf.

my php code is

$pdf = new FPDI();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetAutoPageBreak(true);
$imgaes= array of images from db 
$x=10;
$y=5;
foreach($imgaes as $image)
{
    $y=$y+5;
    $pdf->SetXY($x,$y);
    $pdf->Image($image,$x,$y,40,40);
}

you can try to create page manually and not use SetAutoPageBreak function

you can do something like this, first you need to set the maximum image inside a page, just said 20 image per page. here we go;

$max=20;
$num=1;
foreach($imgaes as $image)
{
    if ($num mod 20 == 0 && $num > 1){
      $pdf->AddPage();
    }
    $y=$y+5;
    $pdf->SetXY($x,$y);
    $pdf->Image($image,$x,$y,40,40);
    $num++;
}