drenso/pdf-to-image
Composer 安装命令:
composer require drenso/pdf-to-image
包简介
Convert a pdf to an image
关键字:
README 文档
README
This package provides an easy to work with class to convert PDF's to images. It is based on the spatie/pdf-to-image library, which relied on Imagick for the conversion. This library relies on GD instead.
Requirements
You should have Ghostscript installed. See issues regarding Ghostscript.
Installation
The package can be installed via composer:
composer require drenso/pdf-to-image
Usage
Converting a pdf to an image is easy.
$pdf = new Drenso\PdfToImage\Pdf($pathToPdf); $pdf->saveImage($pathToWhereImageShouldBeStored);
If the path you pass to saveImage has the extensions jpg, jpeg, or png the image will be saved in that format.
Otherwise the output will be a jpg.
Other methods
You can get the total number of pages in the pdf:
$pdf->getNumberOfPages(); //returns an int
By default the first page of the pdf will be rendered. If you want to render another page you can do so:
$pdf->setPage(2) ->saveImage($pathToWhereImageShouldBeStored); //saves the second page
You can override the output format:
$pdf->setOutputFormat(ExportFormatEnum::PNG) ->saveImage($pathToWhereImageShouldBeStored); //the output wil be a png, no matter what
You can set the quality of compression (this depends on the export format, see the GD documentation for more details):
$pdf->setCompressionQuality(100); // sets the compression quality to maximum
You can specify the width to scale down the resulting image:
$pdf ->setWidth(400) ->saveImage($pathToWhereImageShouldBeStored);
Issues regarding Ghostscript
This package uses Ghostscript through Imagick. For this to work Ghostscripts gs command should be accessible from the PHP process. For the PHP CLI process (e.g. Laravel's asynchronous jobs, commands, etc...) this is usually already the case.
However for PHP on FPM (e.g. when running this package "in the browser") you might run into the following problem:
Uncaught ImagickException: FailedToExecuteCommand 'gs'
This can be fixed by adding the following line at the end of your php-fpm.conf file and restarting PHP FPM. If you're unsure where the php-fpm.conf file is located you can check phpinfo(). If you are using Laravel Valet the php-fpm.conf file will be located in the /usr/local/etc/php/YOUR-PHP-VERSION directory.
env[PATH] = /usr/local/bin:/usr/bin:/bin
This will instruct PHP FPM to look for the gs binary in the right places.
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
drenso/pdf-to-image 适用场景与选型建议
drenso/pdf-to-image 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 74.13k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 02 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「pdf」 「convert」 「pdf-to-image」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 drenso/pdf-to-image 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 drenso/pdf-to-image 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 drenso/pdf-to-image 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provides a simple decimal/roman number converter
A library that provides a simple infrastructure to create your own converters and to perform any conversion you want
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
Convert xml to array
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
统计信息
- 总下载量: 74.13k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-13