Skip to content

Commit

Permalink
Fix for devbian arch
Browse files Browse the repository at this point in the history
  • Loading branch information
MaestroError committed Aug 2, 2023
1 parent 74a14b1 commit bc1e640
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ The easiest way to convert HEIC/HEIF images to JPEG with PHP and Laravel framewo
- [Installation](#installation)
- [Usage](#usage)
- [For MacOS users](#for-macos-users)
- [Force arm64 for linux](#force-arm64-for-linux)
- [isHeic method](#isheic-method)
- [convertFromUrl method](#convertfromurl-method)
- [Mdat issue](##handling-mdat-file-conversion-issues)
Expand All @@ -29,6 +30,12 @@ It should detect the OS itself, but if you want to specify architecture, it is r
// 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, you can force it to use in `convert` and `convertFromUrl` by passing true as third argument:
```php
Maestroerror\HeicToJpg::convert("image1.heic", "", true)->saveAs("image.jpg");
```

#### isHeic method
Before converting, you can use the isHeic method (contributed by [pbs-dg](https://github.com/pbs-dg)) to check if a file is HEIC format.
Expand Down
26 changes: 18 additions & 8 deletions src/HeicToJpg.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class HeicToJpg {
*/
protected string $arch = "amd64";

/**
* Force arm64
*
* @var bool
*/
protected bool $forceArm = false;

/**
* Location of the "heif-converter-image" package's executable
*
Expand Down Expand Up @@ -139,10 +146,12 @@ public function checkLinuxOS(): self {
$this->os = "linux";
}

// Fix for the Debian (10/11 Versions), visit the issue for more info (https://github.com/MaestroError/php-heic-to-jpg/issues/22)
$debian = str_contains($arch, "x86_64") && $this->os == "linux";
if (str_contains($arch, "aarch64") || str_contains($arch, "arm64")){
$this->arch = "arm64";
}

if (str_contains($arch, "aarch64") || $debian){
// Fix for the Debian (10/11 Versions), visit the issue for more info (https://github.com/MaestroError/php-heic-to-jpg/issues/22)
if ($this->forceArm) {
$this->arch = "arm64";
}

Expand All @@ -164,7 +173,8 @@ public function checkWindowsOS(): self {
return $this;
}

public function checkOS() {
public function checkOS($forceArm = false) {
$this->forceArm = $forceArm;
return $this->checkWindowsOS()->checkLinuxOS()->checkMacOS();
}

Expand Down Expand Up @@ -301,10 +311,10 @@ private function setDarwinExe(string $arch) {
}
}

public static function convert(string $source, string $converterPath = "")
public static function convert(string $source, string $converterPath = "", $forceArm = false)
{
return (new self)
->checkOS()
->checkOS($forceArm)
->setConverterLocation($converterPath)
->convertImage($source);
}
Expand All @@ -314,13 +324,13 @@ public static function convertOnMac(string $source, string $arch = "amd64", stri
return (new self)->setConverterLocation($converterPath)->convertImageMac($source, $arch);
}

public static function convertFromUrl(string $url, string $converterPath = "") {
public static function convertFromUrl(string $url, string $converterPath = "", $forceArm = false) {
// Download image
$newFileName = "HTTP" . "-" . uniqid(rand(), true);
file_put_contents($newFileName, file_get_contents($url));
// Convert image
$object = (new self)
->checkOS()
->checkOS($forceArm)
->setConverterLocation($converterPath)
->convertImage($newFileName);

Expand Down

0 comments on commit bc1e640

Please sign in to comment.