[solved] HEIC - `ImagickException: Unable to set image format`

I’ve compiled from code latest ImageMagic with heic support and module is enabled and working on the PHP side. But, as soon as i access the heic file an exception is thown giving not much details other than it was unable to set image format…

I’m attaching the debug trace of that exception:

{
  "reqId": "vqjXxuUSwb5VqYCdA9e4",
  "level": 3,
  "time": "2021-10-10T11:06:58+00:00",
  "remoteAddr": "192.168.100.21",
  "user": "korisnik",
  "app": "core",
  "method": "GET",
  "url": "/core/preview?fileId=460464&x=256&y=256&a=true&v="33ae594fa019d93641f208facc97d8b1"",
  "message": "File: /korisnik/files/Iphone Media (autobackup)/20200816 134424 6329.heic Imagick says: Unable to set image format",
  "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36",
  "version": "22.2.0.2",
  "exception": {
    "Exception": "ImagickException",
    "Message": "Unable to set image format",
    "Code": 1,
    "Trace": [
      {
        "file": "/home/nextcloud/www/versions/nextcloud-22.2.0/lib/private/Preview/HEIC.php",
        "line": 106,
        "function": "setImageFormat",
        "class": "Imagick",
        "type": "->"
      },
      {
        "file": "/home/nextcloud/www/versions/nextcloud-22.2.0/lib/private/Preview/HEIC.php",
        "line": 64,
        "function": "getResizedPreview",
        "class": "OC\\Preview\\HEIC",
        "type": "->"
      },
      {
        "file": "/home/nextcloud/www/versions/nextcloud-22.2.0/lib/private/Preview/GeneratorHelper.php",
        "line": 62,
        "function": "getThumbnail",
        "class": "OC\\Preview\\HEIC",
        "type": "->"
      },
      {
        "file": "/home/nextcloud/www/versions/nextcloud-22.2.0/lib/private/Preview/Generator.php",
        "line": 245,
        "function": "getThumbnail",
        "class": "OC\\Preview\\GeneratorHelper",
        "type": "->"
      },
      {
        "file": "/home/nextcloud/www/versions/nextcloud-22.2.0/lib/private/Preview/Generator.php",
        "line": 140,
        "function": "getMaxPreview",
        "class": "OC\\Preview\\Generator",
        "type": "->"
      },
      {
        "file": "/home/nextcloud/www/versions/nextcloud-22.2.0/lib/private/Preview/Generator.php",
        "line": 109,
        "function": "generatePreviews",
        "class": "OC\\Preview\\Generator",
        "type": "->"
      },
      {
        "file": "/home/nextcloud/www/versions/nextcloud-22.2.0/lib/private/PreviewManager.php",
        "line": 189,
        "function": "getPreview",
        "class": "OC\\Preview\\Generator",
        "type": "->"
      },
      {
        "file": "/home/nextcloud/www/versions/nextcloud-22.2.0/core/Controller/PreviewController.php",
        "line": 169,
        "function": "getPreview",
        "class": "OC\\PreviewManager",
        "type": "->"
      },
      {
        "file": "/home/nextcloud/www/versions/nextcloud-22.2.0/core/Controller/PreviewController.php",
        "line": 142,
        "function": "fetchPreview",
        "class": "OC\\Core\\Controller\\PreviewController",
        "type": "->"
      },
      {
        "file": "/home/nextcloud/www/versions/nextcloud-22.2.0/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 217,
        "function": "getPreviewByFileId",
        "class": "OC\\Core\\Controller\\PreviewController",
        "type": "->"
      },
      {
        "file": "/home/nextcloud/www/versions/nextcloud-22.2.0/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 126,
        "function": "executeController",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->"
      },
      {
        "file": "/home/nextcloud/www/versions/nextcloud-22.2.0/lib/private/AppFramework/App.php",
        "line": 156,
        "function": "dispatch",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->"
      },
      {
        "file": "/home/nextcloud/www/versions/nextcloud-22.2.0/lib/private/Route/Router.php",
        "line": 301,
        "function": "main",
        "class": "OC\\AppFramework\\App",
        "type": "::"
      },
      {
        "file": "/home/nextcloud/www/versions/nextcloud-22.2.0/lib/base.php",
        "line": 1000,
        "function": "match",
        "class": "OC\\Route\\Router",
        "type": "->"
      },
      {
        "file": "/home/nextcloud/www/versions/nextcloud-22.2.0/index.php",
        "line": 36,
        "function": "handleRequest",
        "class": "OC",
        "type": "::"
      }
    ],
    "File": "/home/nextcloud/www/versions/nextcloud-22.2.0/lib/private/Preview/HEIC.php",
    "Line": 106,
    "CustomMessage": "File: /korisnik/files/Iphone Media (autobackup)/20200816 134424 6329.heic Imagick says: Unable to set image format"
  }
}

Nextcloud version: 22.2.0
OS: Ubuntu 20.04 / Nginx
PHP version: 8.0
ImageMagic 7 with HEIC support

You didn’t forget to install and enable the HEIC/HEIF Image Converter from the Nextcloud App Store, did you?

Hi Tamsy, no, the plugin app was installed and enabled. Also, in config, there’s a definition of preview generation provider, but still, the error in error log appears regularly when the heic file is accessed…

That is strange. Does HEIC, HEIF show up at the phpinfo.php-page under “imagick” → “ImageMagick supported formats”

imagick

That was the first thing I checked after compiling ImageMagic and it is there… According to everything, it should work. I think that I’ll start with debugging things around, what is passed to HEIC, what happens in each of the steps - just need to read the developers doc to see what’s the syntax for the log class. Will put more info here once I debug things around…

One more thing, do I really need the HEIC/HEIF image converter app for this to be natively supported or not? Initially, I got an impression that I don’t, but once I saw that it isn’t working, I tried to install it, then found out that it isn’t working with it either and then you also asked if I forgot to install that app maybe…

Anyways, here’s my phpinfo part related to imagick, it’s the same as yours (just yours has slightly more supported files, but that isn’t the case here… heic is supported and should work)
image

Actually, I just figured out that in imagick list there’s no jpg or png or any of these ‘common’ formats… hm…

@Tamsy tnx, your comment actually lead me in the right direction. I did have the heic support, but didn’t have for jpg, png, and almost any of the common formats :slight_smile:

After recompiling both ImageMagick and imagick, and restarting phpfpm and nginx, all works as expected…

image

Great to hear that you got it sorted out by recompiling ImageMagick including the common formats thus the HEIC files are now correctly displayed :+1:t3:

Especially JPEG is mandatory because the HEIC/HEIF Image Converter displays the HEIC-format by converting it to JPEG on-the-fly.

Maybe you want to set the thread’s topic to [solved] to make it easier for other users with similiar problems?

Hi Tamsy, i changed the title of the post and selected your answer about supported formats as a solution as it did actually lead me to the solution :slight_smile:

1 Like