Docker (compose) php apache. Imagick with heic support [closed]

We’re running a website for our community on docker (compose) and now we would like to enable heic support for imagick such that apple users can upload images which are then converted to jpeg.

We have been able to enable imagick and gd support but heic is another issue.

FROM php:8.1-apache

RUN a2enmod rewrite 

# Install system dependencies
RUN apt-get update && apt-get install -y 
      git 
      libicu-dev 
      libc-client-dev
      zlib1g-dev 
      g++
      libpq-dev 
      libmcrypt-dev 
      git 
      libkrb5-dev

# Install system dependencies for zipping
RUN apt-get install -y 
      libzip-dev 
      zip 
      unzip

# Install system deps for imagick
RUN apt-get install -y 
      libpng-dev 
      libjpeg-dev 
      libwebp-dev 
      libfreetype6-dev 
      libonig-dev 
      libxml2-dev 
      libheif-dev 
      libde265-dev 
      imagemagick 
      libmagickwand-dev 
      && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install pdo pdo_mysql mysqli
RUN docker-php-ext-configure intl
RUN docker-php-ext-install 
      intl
      # mbstring 
      # curl 
      # json 
      # zip
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl && docker-php-ext-install imap && docker-php-ext-enable imap

# Install PHP GD extension
RUN apt-get install -y zlib1g-dev libpng-dev libjpeg-dev
RUN docker-php-ext-configure gd 
      --with-jpeg 
      --with-freetype 
      && docker-php-ext-install gd

# Install PHP Imagick extension via PECL and enable it
RUN apt-get update && apt-get install -y libmagickwand-dev 
    && pecl install imagick 
    && docker-php-ext-enable imagick

RUN convert -list format | grep HEIC || echo "HEIC format not found in ImageMagick"


# RUN usermod -u ${uid} www-data 
#     && groupmod -g ${uid} www-data;

My test code:

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['image'])) {
    $fileTmp = $_FILES['image']['tmp_name'];
    $fileExt = strtolower(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION));

    $imagick = new Imagick($fileTmp);
    
}
?>

<!DOCTYPE html>
<html>
<head><title>HEIC to JPEG</title></head>
<body>
    <h1>Upload HEIC Image</h1>
    <form method="post" enctype="multipart/form-data">
        <input type="file" name="image" accept=".heic">
        <button type="submit">Convert to JPEG</button>
    </form>
</body>
</html>

The issue:
Fatal error: Uncaught ImagickException: Invalid filename provided in /var/www/html/upload-test.php:8 Stack trace: #0 /var/www/html/upload-test.php(8): Imagick->__construct('') #1 {main} thrown in /var/www/html/upload-test.php on line 8

We can’t find “a simple solution” that is like enabling gd or imagick with heic but only solutions that require us to build imagick from source and then enable heic.

Is doing so, by building from source and enabling heic, the only possible method?
What is a good alternative for converting iphone images to jpeg / png on our website with ease or enabling imagick to convert heic to jpeg format with ease?