Last active
January 1, 2026 03:22
-
-
Save saeedvir/1b2685370e94fecb36bb843514585a9a to your computer and use it in GitHub Desktop.
convert HEIC to other format in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* how to install imagick ? | |
| go to | |
| https://pecl.php.net/package/imagick | |
| for windows use "DLL" links | |
| */ | |
| function heicToImage(string $source, string $destination, string $format = 'jpg'): bool | |
| { | |
| if (!extension_loaded('imagick')) { | |
| return false; | |
| } | |
| $img = new Imagick($source); | |
| $img->setImageFormat($format); | |
| $img->setImageCompressionQuality(90); | |
| $result = $img->writeImage($destination); | |
| $img->clear(); | |
| $img->destroy(); | |
| return $result; | |
| } | |
| function heicToImageCLI(string $source, string $destination): bool | |
| { | |
| if (!file_exists($source)) { | |
| return false; | |
| } | |
| $cmd = sprintf( | |
| 'heif-convert %s %s 2>&1', | |
| escapeshellarg($source), | |
| escapeshellarg($destination) | |
| ); | |
| exec($cmd, $output, $code); | |
| return $code === 0 && file_exists($destination); | |
| } | |
| function heicToJpgFFmpeg(string $source, string $destination): bool | |
| { | |
| $cmd = sprintf( | |
| 'ffmpeg -y -i %s %s 2>&1', | |
| escapeshellarg($source), | |
| escapeshellarg($destination) | |
| ); | |
| exec($cmd, $out, $code); | |
| return $code === 0 && file_exists($destination); | |
| } |
Author
saeedvir
commented
Jan 1, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment