/php-heic-to-jpg

The easiest way to convert HEIC images to JPEG with PHP and Laravel framework

Primary LanguagePHPMIT LicenseMIT

php-heic-to-jpg

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" (aarm64, M1)

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

Credits

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

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