maestroerror/php-heic-to-jpg 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

maestroerror/php-heic-to-jpg

Composer 安装命令:

composer require maestroerror/php-heic-to-jpg

包简介

Converts HEIC/HEIF image to JPG type, without any dependencies

README 文档

README

The easiest way to convert HEIC/HEIF images to JPEG with PHP and Laravel framework. It uses binary file created with Go language and has no dependencies on any other PHP libraries, extensions or third-part software

Installation

Run command in your project's root directory

composer require maestroerror/php-heic-to-jpg

Usage

Using the class "HeicToJpeg" is extremely simple. You need full location of any HEIC image to pass in "convert" function and call "saveAs" (save as file) or "get" (get file contents) methods.

// 1. save as file
Maestroerror\HeicToJpg::convert("image1.heic")->saveAs("image1.jpg");
// 2. get content (binary) of converted JPG
$jpg = Maestroerror\HeicToJpg::convert("image1.heic")->get();

For MacOS users

It should detect the OS itself, but if you want to specify architecture, it is recommended to use convertOnMac instead. The second argument is architecture of your system, by default set as "amd64", but you can specify "arm64" (AArch64, M1)
Note: As reported by several users, M1 Macbook works on amd64 binary file, so if arm64 doesn't work for you, just try convertOnMac("image1.heic")

// By default
Maestroerror\HeicToJpg::convertOnMac("image1.heic", "arm64")->saveAs("image1.jpg");

Force arm64 for linux

In case of linux, for some reason, if it doesn't detect your architecture correct or just the php-heic-to-jpg-linux-arm64 binary is working for you well, (From v1.0.4) you can force it to use in convert and convertFromUrl by passing true as third argument:

Maestroerror\HeicToJpg::convert("image1.heic", "", true)->saveAs("image.jpg");

isHeic method

Before converting, you can use the isHeic method (contributed by pbs-dg) to check if a file is HEIC format.

$fileIsHeic = HeicToJpg::isHeic("image.heic");
if ($fileIsHeic) {
    // Your code
}

convertFromUrl method

If your image is available publicly, you can easily convert and save it in your file system using convertFromUrl method:

Maestroerror\HeicToJpg::convertFromUrl("https://github.com/MaestroError/php-heic-to-jpg/raw/maestro/tests/Unit/images/image1.heic")->saveAs("image1.jpg");

Handling 'mdat' File Conversion Issues

If you encounter an issue where the module cannot convert certain images produced by Samsung devices (detailed in this issue), resulting in the error error reading "meta" box: got box type "mdat" instead, you can take the following steps:

heif-converter-image is already required by composer in this (php-heic-to-jpg) package. heif-converter-image depends on libheif and provides installation scripts for various platforms refer to it's documentation.

  • Ensure you have maestroerror/heif-converter required in composer by running composer require maestroerror/heif-converter.

  • Make sure libheif is installed on your system. You can check the libheif for installation instructions or use installation script for your platform provided by heif-converter-image.

The php-heic-to-jpg package automatically detects the presence of the heif-converter-image package and will attempt to use its Command Line Interface (CLI) executable for conversion if default conversion fails.

In case the package cannot find the heif-converter-image CLI, you can specify the path as an argument in the convert and convertOnMac methods like so:

HeicToJpg::convert("image.heic", "path/to/your/bin/heif-converter-{linux/windows/macos}")->saveAs("image.jpg");
HeicToJpg::convertOnMac("image.heic", "arm64", "path/to/your/bin/heif-converter-macos")->saveAs("image.jpg");
HeicToJpg::convertFromUrl("SOME_URL", "path/to/your/bin/heif-converter-{linux/windows/macos}")->saveAs("image.jpg");

With these steps, you should be able to handle the conversion of images that were previously causing issues.

Credits

I would like to say thanks to these people. Their work helped me to build heicToJpg file with Go:

Support

Support Our Work? 🌟 You can help us keep the code flowing by making a small donation. Every bit of support goes a long way in maintaining and improving our open-source contributions. Click the button below to contribute. Thank you for your generosity!

Or use QR code:

Log

27/02/2023
Built executables for MacOs (OS X / Darwin) with command sudo /home/maestroerror/go/bin/xgo --targets=darwin/* github.com/MaestroError/php-heic-to-jpg
04/03/2023
Added pest test and workflows for linux, windows and macos. Run tests locally with ./vendor/bin/pest

To Do
  • Find out if it can be used with docker CLI command from PHP, add in docs if yes
  • Try to update to Go 1.21 version
  • Add github action for generating executables
  • Add issue #33 and solution as arm64 example
  • Add changes from issue #28 (try/catch)
  • Add alternative packages in Docs from this issue comment

maestroerror/php-heic-to-jpg 适用场景与选型建议

maestroerror/php-heic-to-jpg 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 996.87k 次下载、GitHub Stars 达 185, 最近一次更新时间为 2023 年 01 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 maestroerror/php-heic-to-jpg 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 996.87k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 187
  • 点击次数: 26
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 185
  • Watchers: 3
  • Forks: 25
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-25