PDF to Image Converter Info - thepoopooman652/proishs-webtools GitHub Wiki
pdf2img — PDF to image converter
Overview
pdf2img converts uploaded PDF files into raster images, producing one image per PDF page. The tool supports PNG, JPEG and WEBP output formats and can produce a single image (for single-page PDFs) or a ZIP archive containing one image per page.
Features
- Upload a PDF or provide it via programmatic POST.
- Output formats: PNG, JPEG, WEBP.
- Control rasterization DPI (dots-per-inch) for resolution control.
- Control JPEG/WEBP quality.
- Optionally package multi-page outputs into a ZIP archive.
- Uses the PHP
Imagickextension when available; falls back to the ImageMagick CLI (magickorconvert) if present.
Dependencies
- Preferred: PHP
Imagickextension (ImageMagick binding for PHP). Ensure the extension is enabled in the PHP build used by the webserver. - Fallback: ImageMagick command-line tools (
magickorconvert) available in PATH. Ghostscript is commonly required by ImageMagick to rasterize PDFs.
Quick start (local)
- Start PHP's built-in server in the
pdf2imgfolder:
cd 'C:\Users\Administrator\Documents\GitHub\proishs-webtools\converters\pdf2img'
php -S 127.0.0.1:8000 -t .
- Open
http://127.0.0.1:8000/index.phpin a browser and upload a PDF. Adjust DPI, quality and output format, then press Convert.
Notes on server configuration
- Imagick: enable the extension in
php.ini(Windows builds often include a DLL; Linux installs via package manager or pecl). When Imagick is present the tool will use it by default for conversion. - ImageMagick CLI: if Imagick is not available, the script attempts to use
magickorconvertcommands. On Windows install ImageMagick and ensure the installation directory is added to PATH. On Linux install theimagemagickpackage and Ghostscript (ghostscript/gs) to handle PDF rasterization.
Behavior details
- DPI: Controls rasterization resolution. Higher values produce larger, higher-detail images but increase CPU and memory usage.
- Quality: Controls JPEG/WEBP compression quality (ignored for PNG). Range 10–100.
- Output packaging: For multi-page PDFs, outputs are zipped by default if the Zip option is selected; otherwise images can be downloaded individually by modifying the page behavior.
Programmatic usage
Example curl POST (returns a ZIP if multiple pages and zip option enabled):
curl -F "[email protected]" -F "format=png" -F "dpi=150" -F "quality=90" -F "zip=1" http://127.0.0.1:8000/index.php -o output.zip
Output file naming
- Single-page PDF: the returned file is the image for page 1 with an appropriate extension.
- Multi-page PDF: images are named
page-001.png,page-002.png, ... inside the ZIP.
Testing checklist
- Convert a single-page PDF to PNG and verify the resulting image renders correctly.
- Convert a multi-page PDF to PNG and confirm the ZIP contains all page images named sequentially.
- Try JPEG and WEBP outputs and validate the
qualityparameter changes file size and visual quality. - Test with varying
dpivalues (72, 150, 300) and verify resolution changes. - If Imagick is unavailable, ensure ImageMagick CLI is available and test the fallback path.
Limitations and notes
- The conversion process can be memory- and CPU-intensive for high DPI values and large PDFs. Monitor server resources when using in production.
- The script uses temporary files; ensure the webserver's temp directory has sufficient space and appropriate cleanup policies.
- For very large PDFs or batch processing, consider an asynchronous worker queue rather than synchronous web handling.
Changelog
- 2025-11-07: Initial implementation and documentation added.
This README documents the converter's options, dependencies and usage. For production deployments, configure appropriate timeouts, resource limits and storage policies before exposing the tool publicly.