定制 hyder/converter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hyder/converter

Composer 安装命令:

composer require hyder/converter

包简介

A Laravel package that provides an easy-to-use interface to convert PDF files to images using the Imagick PHP extension.

README 文档

README

A Laravel package that allows you to convert PDF files to images. The package uses Imagick PHP extension and GhostScript to convert PDF files to images.

Requirements

  • PHP "^7.3|^8.0"

  • Imagick PHP extension
    Enable the Imagick extension in your php.ini file by uncommenting or adding the following line:

extension=imagick
  • Ghostscript
    Verify that Ghostscript is installed by running the following command:
gs -v

This should display the version number of Ghostscript.

Installation

You can install the package via composer:

composer require hyder/converter

Configuration

You can publish the configuration file to customize the package settings. To publish the configuration file, run the following command:

php artisan vendor:publish --provider="Hyder\Converter\ConverterServiceProvider" --tag="config"

This will create a config/converter.php file where you can configure the package settings.

Optional

The service provider will automatically get registered. Or you may manually add the service provider in your config/app.php file:

'providers' => [
    // ...
    Hyder\Converter\ConverterServiceProvider::class,
];

Usage

Here's an example of how to convert a PDF file to an image:

use Hyder\Converter\Facades\PdfToImage;

// Minimalistic
$response = PdfToImage::path('/path/to/file.pdf')
    ->save();

// Customize output
$response = PdfToImage::path('/path/to/file.pdf')
    ->format('png')
    ->resolution(200)
    ->maxLimit(5)
    ->setPage('1-3,5')
    ->toDir('/path/to/directory')
    ->save('output-image-name');

Available Methods

Here are the available methods of the package:

path(string $path)

This method sets the path of the PDF file you want to convert to an image.

format(string $format)

This method sets the output format of the image. The supported formats are JPEG, JPG, and PNG.

resolution(int $dpi)

This method sets the resolution of the output image in dots per inch (dpi). The higher the resolution, the better the quality of the image, but also the larger the file size.

maxLimit(int $max)

This method sets a maximum limit for the number of pages to be converted. If the PDF file has more pages than this limit, only the first $max pages will be converted.

setPage($pages)

This method sets the pages of the PDF file that you want to convert. The pages can be specified as single page numbers (e.g. 1,2,3), a range of pages (e.g. 1-3), or a combination of both (e.g. 1,2,3-5). By default only the first page will be converted.

allPage()

This method is used to set all pages of the PDF file for conversion to images. It doesn't make any sense to use maxLimit() or setPage() when using allPage(). If you call these methods before allPage(), they will be ignored.

toDir(string $storageTo)

This method sets the directory where the converted images will be saved. If no directory is specified, the default directory will be used.

save(string $name = "")

This method converts the PDF file to an image and saves it to the specified directory. If no name is specified, the image will be saved with a random name.

Error Handling

After enabling imagick you may get an error in the live server. ImageMagick has some security policies disabling some rights for security reasons. You will have to edit a config file to re-enable the action you need.

Open /etc/ImageMagick-6/policy.xml with your favorite text editor, find the line and replace "none" by "read|write"

Open the file

sudo nano /etc/ImageMagick-6/policy.xml

Find and edit the line

<policy domain="coder" rights="none" pattern="PDF" />

To

<policy domain="coder" rights="read|write" pattern="PDF" />

You can check Here for better understanding.

Credits

Imagick

Contributing

If you would like to contribute to this package, please create a pull request or open an issue.

License

The PDF to Image Converter package is open-source software licensed under the MIT license.

hyder/converter 适用场景与选型建议

hyder/converter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「image」 「pdf」 「converter」 「laravel」 「pdf-to-image」 「hyder」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 hyder/converter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hyder/converter 我们能提供哪些服务?
定制开发 / 二次开发

基于 hyder/converter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 30
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-08