MaestroError / php-heic-to-jpg

The easiest way to convert HEIC images to JPEG with PHP and Laravel framework
MIT License
148 stars 20 forks source link

Couldn't covert HEIC to JPG #13

Closed XbNz closed 10 months ago

XbNz commented 1 year ago
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"'

Output of command:

[1]    41341 killed

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

Fails:

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

Passes:

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.

MaestroError commented 1 year ago

Hey, @XbNz! Thanks for contacting 👍 Yes, it is recommended to use converOnMac method for MacOS users to specify the architecture, because sometimes it doesn't find the correct one

XbNz commented 1 year ago

Hey, @XbNz! Thanks for contacting 👍 Yes, it is recommended to use converOnMac method for MacOS users to specify the architecture, because sometimes it doesn't find the correct one

Hey,

The issue actually isn't platform detection. It correctly detects my M1 chip and uses the arm64 bin. But the arm64 bin just doesn't work. Even if I do ->convertOnMac('arm64') it will fail.

MaestroError commented 1 year ago

Hmm.. but it worked on M1, try and run this command manually in your console:

/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"

@XbNz And how HeicToJpg::convertOnMac($tempPath, 'amd64')->saveAs($tempPath); passes? It shouldn't work on M1, did you try it on another device?

XbNz commented 1 year ago

try and run this command manually in your console

./vendor/maestroerror/php-heic-to-jpg/src/../bin/php-heic-to-jpg-darwin-arm64
[1]    95938 killed

@XbNz And how HeicToJpg::convertOnMac($tempPath, 'amd64')->saveAs($tempPath); passes? It shouldn't work on M1, did you try it on another device?

No idea. It works though:

./vendor/maestroerror/php-heic-to-jpg/src/../bin/php-heic-to-jpg-darwin-amd64

Not enough arguments, needs: [command] [file1.heic] [file2.jpg]
Created by MaestroError

Of course, here I'm not passing any arguments, but even when including arguments, the arm process crashed and gets killed.

I have not tried it on any other machines.

MaestroError commented 1 year ago

@XbNz So if amd64 works for you, Why don't you just use it? (convertOnMac($tempPath, 'amd64')) it seems you have M1 but with amd64 architecture. Can you check your arch?

XbNz commented 1 year ago

@XbNz So if amd64 works for you, Why don't you just use it? (convertOnMac($tempPath, 'amd64')) it seems you have M1 but with amd64 architecture. Can you check your arch?

uname -m output: arm64

The reason why I don't use it is because production runs on x86 and I'd have to keep switching it manually in the codebase. I can attach it to an env var but I'm just wondering if anyone else is having this issue with your bins.

MaestroError commented 1 year ago

@XbNz Wow! It is a really strange issue 😄 Not sure for now, I know who uses the amd64, but he isn't on M1, so not sure what is the problem here.

MaestroError commented 1 year ago

And I don't know anybody who uses it this way: convertOnMac($tempPath, 'arm64')

DanielGSoftware commented 1 year ago

@XbNz Wow! It is a really strange issue 😄 Not sure for now, I know who uses the amd64, but he isn't on M1, so not sure what is the problem here.

I think the mapping isn't entirely correct. I ran into the same issue some time ago. I believe M1 is always arm64 arch, can't be amd64.

MaestroError commented 1 year ago

Hey, @XbNz ! Any updates? Did you fix the issue?

SkyNetRu commented 1 year ago

Hi @MaestroError, I get this error Couldn't convert HEIC to JPG: 'Error while converting C:\\OpenServer\\domains\\sphinx-search-api\\public/temp/IMG_4672.heic: error reading \"ftyp\" box: read C:\\OpenServer\\domains\\sphinx-search-api\\public/temp/IMG_4672.heic: Incorrect function.\\nCreated by MaestroError' | Bin used: 'heicToJpg.exe' HEIC: 'C:\\OpenServer\\domains\\sphinx-search-api\\public/temp/IMG_4672.heic' Full Command: 'C:\\OpenServer\\domains\\sphinx-search-api\\vendor\\maestroerror\\php-heic-to-jpg\\src/../bin/heicToJpg.exe \"C:\\OpenServer\\domains\\sphinx-search-api\\public/temp/IMG_4672.heic\" \"C:\\OpenServer\\domains\\sphinx-search-api\\public/temp/IMG_4672.heic-75242546364c003ac720153.71727791\"' Output from heif-converter-image exe:

Using windows

On server Ubuntu same

Couldn't convert HEIC to JPG: 'Error while converting /var/www/search-service-sphinx/public/temp/IMG_4672.heic: error reading \"ftyp\" box: read /var/www/search-service-sphinx/public/temp/IMG_4672.heic: is a directory\\nCreated by MaestroError' | Bin used: 'heicToJpg' HEIC: '/var/www/search-service-sphinx/public/temp/IMG_4672.heic' Full Command: '/var/www/search-service-sphinx/vendor/maestroerror/php-heic-to-jpg/src/../bin/heicToJpg \"/var/www/search-service-sphinx/public/temp/IMG_4672.heic\" \"/var/www/search-service-sphinx/public/temp/IMG_4672.heic-203845678564c00613e24bc0.96288394\"' Output from heif-converter-image exe:

XbNz commented 1 year ago

Hey, @XbNz ! Any updates? Did you fix the issue?

Missed the notification 😄

No, I was not able to find a fix. The solution for me was to use the Linux binaries in production, and when I'm running my test suite on Mac, I need to manually set it to use the convertOnMac AMD64 binary which works for me, as I mentioned previously.

SkyNetRu commented 1 year ago

@XbNz could you please explan how to use Linux binaries, thanks in advance

XbNz commented 1 year ago

@XbNz could you please explan how to use Linux binaries, thanks in advance

You do not have to set the binaries manually. The package should detect your operation system and use the corresponding binaries. In my case, this functionality is failing on MacOS, but works well in my production environment.

Based on your error message, it seems like '/var/www/search-service-sphinx/vendor/maestroerror/php-heic-to-jpg/src/../bin/heicToJpg \"/var/www/search-service-sphinx/public/temp/IMG_4672.heic\" \"/var/www/search-service-sphinx/public/temp/IMG_4672.heic-203845678564c00613e24bc0.96288394\"' is causing a failure. Try to run this command directly in your terminal.

SkyNetRu commented 1 year ago

@XbNz I run command ubuntu@ip-xxx-xxxx-xx:/var/www/search-service-sphinx/public/temp$ /var/www/search-service-sphinx/vendor/maestroerror/php-heic-to-jpg/src/../bin/heicToJpg \"/var/www/search-service-sphinx/public/temp/IMG_4672.heic\" \"/var/www/search-service-sphinx/public/temp/IMG_4672.heic-203845678564c00613e24bc0.96288394\" and get this Error while converting "/var/www/search-service-sphinx/public/temp/IMG_4672.heic": open "/var/www/search-service-sphinx/public/temp/IMG_4672.heic": no such file or directory Created by MaestroError But in folder I see this file ubuntu@ip-xxx-xxxx-xx:/var/www/search-service-sphinx/public/temp$ dir IMG_4671.heic IMG_4672\ -\ Copy.heic IMG_4672.heic

MaestroError commented 1 year ago

Hi @SkyNetRu! Your original error error reading \"ftyp\" box: is because this package doesn't support some types of HEIC images (also was problems with 'mdat' type), try to install heic-converter-image package according to this documentation

SkyNetRu commented 1 year ago

@MaestroError thank you, but I used this JS library and it cover all my needs https://github.com/alexcorvi/heic2any

MaestroError commented 1 year ago

Thanks for sharing @SkyNetRu 👍

austenc commented 1 year ago

Hey @MaestroError I am attempting to use this project on an M1 Macbook Pro (the first generation one) and running into this too. I tried to debug by running these commands manually from the bin folder:

# This does NOT work, results in "killed" output, no other errors
./php-heic-to-jpg-darwin-arm64 "/Users/austen/Desktop/test.HEIC" "/Users/austen/Desktop/test.jpg" 2>&1

# This does work
./php-heic-to-jpg-darwin-amd64 "/Users/austen/Desktop/test.HEIC" "/Users/austen/Desktop/test.jpg" 2>&1 

Is there something else we can do to debug this? Happy to help out if I can, and thank you for the package!

MaestroError commented 1 year ago

Hello, @austenc! Thank you very much for reaching out! I was sure that M1 was on arm64, but it seems, in our case, it works only with the amd64 build 😄 Not sure how can we debug it, I will just add note in Docs about it 👍 I'm happy you came to offer help, thanks for that ❤️