简体   繁体   中英

Converting PDF to JPG of different sizes in PHP

I want to convert PDF pages to JPEG, but I want each page to be converted to 3 images.

  1. First one is high quality

  2. Second is mid quality

  3. Third is thumb images

I use this code but I did not know how to make it to 3 images:

$im = new Imagick();
$im->setResolution(100,100);
$im->readImage("files/xx.pdf");
$im->setImageFormat('jpeg');
$im->writeImages("files/oman/oman.jpg",false);

This code will only convert each PDF page to one image.

Once you've created the first high res version of the page as a jpg, then just use php gd to resize it by reading in that generated jpg and resizing it down and exporting another jpg. This is the function you want and that page shows a simple example of how to resize images.

UPDATE: This shows a pretty simple tutorial on how to resize with php

UPDATE: Sorry, look at the php.net link above, there are many many examples of how to resize an image, here is a simple one . All you need to do is take what is returned and use imagepng() to save the file locally. (There are similar functions to save gif/jpg)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM