In Imagick I am trying to do the following: When accessing .php already begins the download of .jpg, I do not even need a preview just the multiple download because this .pdf in question will always have two pages, with that fopen I can download only the first page, for some reason it does not download the second page.
pdf_file = './programming/'.$date.'.pdf';
$mpdf->Output($pdf_file);
$img = new imagick();
$img->setResolution(200,200);
$img->readImage($pdf_file);
$img->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
$img->setImageFormat('jpg');
$img->setImageCompressionQuality(85);
$pages = $img->getNumberImages();
if ( $pages ) {
foreach($img as $i => $img_file){
$img_file->writeImage('./programming/('.$i.') '.$date.'.jpg');
$img_path = './programming/('.$i.') '.$date.'.jpg';
header('Content-Type: application/download');
header('Content-Disposition: attachment; filename="('.$i.') '.$date.'.jpg"');
header("Content-Length: " . filesize($img_path));
$fp = fopen($img_path, "rb");
fpassthru($fp);
fclose($fp);
}
} else {
echo '<h2>Not Found.</h2>';
}
$img->clear();
$img->destroy();
If anyone can guide me, I may have missed something!
Thank you in advance for your attention!
Note: The images that represent page 1 and 2 of the .pdf are already saved in ./programming/ folder, the code works well in that case, then the foreach did what I expected, created two images and stored them but only download one with fopen