Skip to content

Instantly share code, notes, and snippets.

@saeedvir
Last active January 1, 2026 03:22
Show Gist options
  • Select an option

  • Save saeedvir/1b2685370e94fecb36bb843514585a9a to your computer and use it in GitHub Desktop.

Select an option

Save saeedvir/1b2685370e94fecb36bb843514585a9a to your computer and use it in GitHub Desktop.
convert HEIC to other format in php
<?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);
}
@saeedvir
Copy link
Author

saeedvir commented Jan 1, 2026

//in laravel
if ($file->getClientOriginalExtension() === 'heic') {
    heicToImageCLI($file->path(), $path.'.jpg');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment