Php heic to jpg

maestroerror / php-heic-to-jpg Goto Github PK

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

Run command in your project’s root directory

composer require maestroerror/php-heic-to-jpg 

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();

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)

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

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 >

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.
Читайте также:  Bitrix забыл пароль php

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-")->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-")->saveAs("image.jpg");

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

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

  • heif parser by @bradfitz (https://github.com/go4org/go4/tree/master/media/heif)
  • libde265 (https://github.com/strukturag/libde265)
  • implementation learnt from libheif (https://github.com/strukturag/libheif)
  • Edd Turtle (https://gophercoding.com/convert-heic-to-jpeg-go/)
  • crazy-max/xgo (https://github.com/crazy-max/xgo)

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

php-heic-to-jpg’s People

Contributors

Stargazers

Watchers

Forkers

php-heic-to-jpg’s Issues

Release for linux ?

Hi,
Would you mind adding a linux release?
Thanks!

Couldn’t convert HEIC to JPG

Hi I’m getting an error message ‘Couldn’t convert HEIC to JPG’. It’s working fine on my local enviroment but when I upload this on my test link its now giving me that error message.

I’ve looked into the file and I found that on line 129
exec($command, $output)
This is not returning anything. Whereas on my local enviroment it is. Any suggestions on how to fix this?

Couldn’t convert HEIC to JPG: » | Bin used: ‘heicToJpg’ HEIC:

I have encountered this situation as well. I am dealing with a local file, and the following is the error message.

Couldn’t convert HEIC to JPG: » | Bin used: ‘heicToJpg’ HEIC: ‘/www/wwwroot/www.mishejia.com/public/uploads/image/20230327/6e09410efcc200d2ab6f99ce705c86a7.HEIC’ Full Command: ‘/www/wwwroot/www.mishejia.com/vendor/maestroerror/php-heic-to-jpg/src/../bin/heicToJpg «/www/wwwroot/www.mishejia.com/public/uploads/image/20230327/6e09410efcc200d2ab6f99ce705c86a7.HEIC» «/www/wwwroot/www.mishejia.com/public/uploads/image/20230327/6e09410efcc200d2ab6f99ce705c86a7.HEIC-1769820766421a9c782d929.90318565″‘

Works on some images and errors with others

Hi @MaestroError — I’m having a problem with some HEIC images (about half) giving an error while converting. Then, other HEIC images convert without issue. It’s the image itself that determines if it fails or not. Any image that fails to convert will keep failing when I try again.

Читайте также:  Html href target top blank

Error:
Fatal error: Uncaught RuntimeException: Couldn’t convert HEIC to JPG: » | Bin used: ‘heicToJpg’ HEIC: ‘/var/www/example.com/public_html/content/images/temp/fails.heic’ Full Command: ‘/var/www/composer/vendor/maestroerror/php-heic-to-jpg/src/../bin/heicToJpg /var/www/example.com/public_html/content/images/temp/fails.heic /var/www/example.com/public_html/content/images/temp/fails.heic-181417596641365983cec09.38828464’ in /var/www/composer/vendor/maestroerror/php-heic-to-jpg/src/HeicToJpg.php:139
Thanks

Couldn’t convert HEIC to JPG: » | Bin used: ‘heicToJpg’ HEIC: ‘explain.heic’

hi there.
i m facing this error on this lib.
can explain or guide me how can i fix this.

Couldn’t convert HEIC to JPG: » | Bin used: ‘heicToJpg’ HEIC: ‘file.com/sample1.heic’ Full Command: ‘/vendor/maestroerror/php-heic-to-jpg/src/../bin/heicToJpg «file.com/sample1.heic» «file.com/sample1.heic-1909936596641d3c86bc59c0.67921754″‘

Couldn’t covert HEIC to JPG

RuntimeException : Couldn't convert HEIC to JPG: '' | Bin used: 'php-heic-to-jpg-darwin-arm64' HEIC: '/private/var/folders/xq/bbvlc8r52gsfpxxg6f7f3_p40000gn/T/bjDSfN' Full Command: '/path/to/project/vendor/maestroerror/php-heic-to-jpg/src/../bin/php-heic-to-jpg-darwin-arm64 "/private/var/folders/xq/bbvlc8r52gsfpxxg6f7f3_p40000gn/T/bjDSfN" "/private/var/folders/xq/bbvlc8r52gsfpxxg6f7f3_p40000gn/T/bjDSfN-6597740986440740f359aa1.01134626"'

Update: still no fix, but I have some more info.

HeicToJpg::convertOnMac($tempPath, 'arm64')->saveAs($tempPath);
HeicToJpg::convertOnMac($tempPath, 'amd64')->saveAs($tempPath);

I’m using an M1 MacBook Air. convert also fails, presumably because the OS is detected as arm64, and the bin for that is failing.

the exec error

Call to undefined function Maestroerror\exec()

when i upload the project on linux shared host

Cannot convert HEIC to JPG on vps, CentOs 7

I tested on my windows local machine and everything works fine. But when I push to production, it breaks giving the error below. I’m using this package in a Laravel Application.

Error: Couldn’t convert HEIC to JPG: » | Bin used: ‘heicToJpg’ HEIC: ‘/tmp/phpZHQoXP’ Full Command: ‘/home/azychu/public_html/core/vendor/maestroerror/php-heic-to-jpg/src/../bin/heicToJpg «/tmp/phpZHQoXP» «/tmp/phpZHQoXP-82110470764956f66edaa89.28636582″‘ Output from heif-converter-image exe: «>

Couldn’t convert HEIC to JPG

I am on Windows 11, using WampServer.
I had no problems with your image test, but with this attached image, It’s not working
image2.zip

PHP Error

I’m getting a PHP error while trying to convert. I’m running PHP 8.2 and GO 1.20.1:

PHP Fatal error: Uncaught Error: Call to a member function convertImage() on null in /home/user/vendor/maestroerror/php-heic-to-jpg/src/HeicToJpg.php:209

I’ve verified that the image path is correct. The same path fed into Imagick works (but fails due to lack of HEIC support), so I don’t think it’s a path issue.

Compatible with Ubuntu?

Hi @MaestroError, sorry for bothering you again so soon! I managed to successfully integrate the package in our code on my macbook M1. However, once deployed on our QA server (ubuntu), I get the Couldn’t convert HEIC to JPG error. I’ve tried all the different methods and arch params, but I can’t seem the get it to work.

Can you confirm that if you know the package should work with ubuntu as the OS?

Your requirements could not be resolved to an installable set of packages.

Many thanks for this package. I am trying to install 1.0 but composer doesn’t seem to like it:

Your requirements could not be resolved to an installable set of packages. Problem 1 - Root composer.json requires maestroerror/php-heic-to-jpg 1.0 -> satisfiable by maestroerror/php-heic-to-jpg[v1.0]. - maestroerror/php-heic-to-jpg v1.0 requires maestroerror/heif-converter dev-maestro -> found maestroerror/heif-converter[dev-maestro] but it does not match your minimum-stability. Installation failed, reverting ./composer.json and ./composer.lock to their original content. 

is there anything I am doing wrong here?

Читайте также:  Javascript вывести массив случайных чисел

Error : The file \»/Applications/MAMP/tmp/php/php7XIB7q\» cannot be opened:

I getting errors on all methods

convert not working on arm64 structure

I searched a solution for manipulating wrong loaded .heic files as jpeg, because I need the exif data from the files.

Your solution was a hope for getting this done.

Unfortunately I’m working on MacOS with ARM structure, which means, even my docker container executing the server runs with aarm64. Executing the convert errors to the following:

qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory PHP Fatal error: Uncaught RuntimeException: Couldn't convert HEIC to JPG: in /var/www/html/vendor/maestroerror/php-heic-to-jpg/src/HeicToJpg.php:77 Stack trace: #0 /var/www/html/vendor/maestroerror/php-heic-to-jpg/src/HeicToJpg.php(33): Maestroerror\HeicToJpg->processImage('/var/www/html/p. ') #1 /var/www/html/vendor/maestroerror/php-heic-to-jpg/src/HeicToJpg.php(123): Maestroerror\HeicToJpg->convertImage('/var/www/html/p. ') #2 /var/www/html/public/test.php(7): Maestroerror\HeicToJpg::convert('/var/www/html/p. ') #3 thrown in /var/www/html/vendor/maestroerror/php-heic-to-jpg/src/HeicToJpg.php on line 77 Fatal error: Uncaught RuntimeException: Couldn't convert HEIC to JPG: in /var/www/html/vendor/maestroerror/php-heic-to-jpg/src/HeicToJpg.php:77 Stack trace: #0 /var/www/html/vendor/maestroerror/php-heic-to-jpg/src/HeicToJpg.php(33): Maestroerror\HeicToJpg->processImage('/var/www/html/p. ') #1 /var/www/html/vendor/maestroerror/php-heic-to-jpg/src/HeicToJpg.php(123): Maestroerror\HeicToJpg->convertImage('/var/www/html/p. ') #2 /var/www/html/public/test.php(7): Maestroerror\HeicToJpg::convert('/var/www/html/p. ') #3 thrown in /var/www/html/vendor/maestroerror/php-heic-to-jpg/src/HeicToJpg.php on line 77

Is there any possibility getting this cool library work on aarm architecture, too?

Linux web 5.15.49-linuxkit #1 SMP PREEMPT Tue Sep 13 07:51:32 UTC 2022 aarch64 GNU/Linux 

How to convert files from an url?

Hi @MaestroError, first I’d like to say thanks for the amazing package! We currently use a external service to convert our heic to jpg’s, but it would be more beneficial to be able to do this directly :).

I’m trying to convert heic files from a amazon s3 url, but unfortunately this doesn’t seem to work. I get Couldn’t convert HEIC to JPG: » | Bin used: ‘php-heic-to-jpg-darwin-amd64’ .

When I try to do it with an a random heic file url I also get the same error.

When using a local path to a file, it all works.

My question is, how do I convert a heic file from an url?

Error reading «meta» box: got box type «mdat» instead

Today, I tried to use your library to convert HEIC to JPEG. However, when I attempted to use it, I encountered an error. I tried to debug the issue by executing the command directly :

/Applications/MAMP/htdocs/captus/vendor/maestroerror/php-heic-to-jpg/src/../bin/php-heic-to-jpg-darwin-amd64 «/pathtomyfile/8ivB0GLCbsWkfeHnfTbzZDC4pJP9YOAFeb9giBCH.heic» «/pathtomyfilet/8ivB0GLCbsWkfeHnfTbzZDC4pJP9YOAFeb9giBCH.heic-1943393784644fce698a1fe9.91263079»

2023/05/01 16:36:39 error reading «meta» box: got box type «mdat» instead

$fileIsHeic = HeicToJpg::isHeic(public_path($data[‘hunts’][$i][‘imagesTemplates’][$k][‘image’]));
if ($fileIsHeic) $imageName = $this->generateRandomString(10);
HeicToJpg::convertOnMac(public_path($data[‘hunts’][$i][‘imagesTemplates’][$k][‘image’]), «amd64»)->saveAs(public_path(«/upload/tmp/test.jpg»));
$data[‘hunts’][$i][‘imagesTemplates’][$k][‘image’] = «/upload/tmp/» . $imageName . «.jpg»;
dump(«ok»);die();
>

Источник

Оцените статью