Skip to content

Support of HEIC / HEIF MimeType in IMagickΒ #263

@JapanDoudou67

Description

@JapanDoudou67

Hello everyone !
First, thank for your work :)

I'm Using the thecodingmachine/php:7.4-v4-fpm image for a project on Symfony.
I activate the ext-imagick extension in my composer.json and PHP_EXTENSION_IMAGICK in my docker-compose.

But my new Imagick() cannot read HEIC images from IPhone :(

I tried to apply this tuto on my current configuration :

https://eplt.medium.com/5-minutes-to-install-imagemagick-with-heic-support-on-ubuntu-18-04-digitalocean-fe2d09dcef1

Here is my DockerCompose :

php_web:
    build: docker/php
    tty: true
    links:
      - postgres
    volumes:
      - ".:/var/www/html"
    depends_on:
      - postgres
    environment:
      PHP_INI_POST_MAX_SIZE: 30M
      PHP_INI_UPLOAD_MAX_FILESIZE: 30M
      PHP_EXTENSION_IMAGICK: 1

Here is my DockerFile :

FROM thecodingmachine/php:7.4-v4-fpm

ENV PHP_EXTENSION_PDO_PGSQL=1
ENV PHP_EXTENSION_APCU=1
ENV PHP_EXTENSION_INTL=1
ENV PHP_EXTENSION_GD=1
ENV PHP_EXTENSION_REDIS=1
ENV PHP_EXTENSION_MYSQLI=0
ENV PHP_EXTENSION_PDO_MYSQL=0
ENV PHP_EXTENSION_XDEBUG=0
ENV PHP_INI_ERROR_REPORTING=0
ENV PHP_INI_MEMORY_LIMIT=256M
ENV PHP_INI_POST_MAX_SIZE: 30M
ENV PHP_INI_UPLOAD_MAX_FILESIZE: 30M
ENV TZ="Europe/Paris"

RUN sudo sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list && \
    sudo apt-get update && \
    sudo apt-get install -y build-essential autoconf libtool git-core && \
    sudo apt-get build-dep -y imagemagick libmagickcore-dev libde265 libheif && \
    cd /usr/src/ && \
    sudo git clone https://github.com/strukturag/libde265.git && \
    sudo git clone https://github.com/strukturag/libheif.git && \
    cd libde265/ && \
    sudo ./autogen.sh && \
    sudo ./configure && \
    sudo make && \
    sudo make install && \
    cd /usr/src/libheif/ && \
    sudo ./autogen.sh && \
    sudo ./configure && \
    sudo make && \
    sudo make install && \
    cd /usr/src/ && \
    sudo wget https://www.imagemagick.org/download/ImageMagick.tar.gz && \
    sudo tar xf ImageMagick.tar.gz && \
    cd ImageMagick-7* && \
    sudo ./configure --with-heic=yes && \
    sudo make && \
    sudo make install && \
    sudo ldconfig

Expected Behavior

Converting a HEIC image to an other format

Current Behavior

The error that Symfony return is : "no decode delegate for this image format `HEIC' @ error/constitute.c/ReadImage/560"
It actualy work if I ry to convert PNG files for sample.

Possible Solution

Support the last Imagick version 3.4.4 with HEIC support (feel free to see the link)

Steps to Reproduce (for bugs)

I'm on Symfony 4.2 with the VichUploader bundle to manage file upload

My code :

<?php

declare(strict_types=1);

namespace App\Manager;

use Symfony\Component\HttpFoundation\File\File;

class ImageConverter {
    /**
     * @param File $myImage
     * @param int $compressionQuality
     * @return string
     * @throws ImagickException
     */
    public static function convertHeicToJpg(File $myImage, int $compressionQuality = 70): string
    {
        $filePath = $myImage->getRealPath();
        $myConvertedImage = $filePath . '_jpg';
        $image = new Imagick($myImage);
        $image->readImage($filePath);
        $image->setImageFormat("jpeg");
        $image->setImageCompressionQuality($compressionQuality);
        $image->writeImage($myConvertedImage);
        $image->clear();
        return $myConvertedImage;
    }
}

Context

We want to allow user to allow HEIC file upload from their iPhone, and convert them to allow user to see theim in our image viewer on every devices

Thank you in advance :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleIssues inactives for a while (automatically)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions