libvips/ruby-vips

VipsForeignLoad error with heic / heif format

matteoinfantino opened this issue · 6 comments

Hi,

when i load a heic / heif file from ActiveStorage i get this error:

/usr/local/bundle/gems/ruby-vips-2.1.4/lib/vips/image.rb:281:in `new_from_file': VipsForeignLoad: "/tmp/ActiveStorage-66424-20230316-104-e3pbun.0629056946261" is not a known file format (Vips::Error)

I noticed that in my suffixes heic / heif are missing doing Vips.get_suffixes. This is the output:

[
    [ 0] ".csv",
    [ 1] ".mat",
    [ 2] ".raw",
    [ 3] ".v",
    [ 4] ".vips",
    [ 5] ".pbm",
    [ 6] ".pgm",
    [ 7] ".ppm",
    [ 8] ".pfm",
    [ 9] ".hdr",
    [10] ".j2k",
    [11] ".jp2",
    [12] ".jpt",
    [13] ".j2c",
    [14] ".jpc",
    [15] ".gif",
    [16] ".png",
    [17] ".jpg",
    [18] ".jpeg",
    [19] ".jpe",
    [20] ".webp",
    [21] ".tif",
    [22] ".tiff",
    [23] ".fits",
    [24] ".fit",
    [25] ".fts"
]

My question is: how can i add these formats in order to correctly load those files? I couldn't figure it out.

Thank you in advance.

Hi @matteoinfantino,

ruby-vips exposes the set of loaders in your libvips binary, so you need to add HEIC support there.

This depends on your platform and how you are managing and deploying your code. You'd need to give some more information before I could help.

Hi @jcupitt, thank you for your reply.

I am using a Docker with Alpine

FROM ruby:3.2.1-alpine3.17

In my Dockerfile I already add libde265 libheif-dev to support the conversion.
Indeed running pkg-config libheif --modversion in my docker, outputs 1.13.0

But entering in rails console, like I said in the previous message, there isn't .heic in Vips.get_suffixes output.
Do you need to know something more about my Dockerfile?

I had a look:

$ docker run -it --rm --entrypoint /bin/sh ruby:3.2.1-alpine3.17
/ # apk add vips
fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/community/x86_64/APKINDEX.tar.gz
(1/48) Installing openexr (3.1.5-r3)
(2/48) Installing libxau (1.0.10-r0)
(3/48) Installing libmd (1.0.4-r0)
(4/48) Installing libbsd (0.11.7-r0)
(5/48) Installing libxdmcp (1.1.4-r0)
(6/48) Installing libxcb (1.15-r0)
(7/48) Installing libx11 (1.8.4-r0)
(8/48) Installing libxext (1.3.5-r0)
(9/48) Installing libxrender (0.9.11-r0)
(10/48) Installing libexpat (2.5.0-r0)
(11/48) Installing brotli-libs (1.0.9-r9)
(12/48) Installing libbz2 (1.0.8-r4)
(13/48) Installing libpng (1.6.38-r0)
(14/48) Installing freetype (2.12.1-r0)
(15/48) Installing fontconfig (2.14.1-r0)
(16/48) Installing pixman (0.42.2-r0)
(17/48) Installing cairo (1.17.6-r3)
(18/48) Installing nghttp2-libs (1.51.0-r0)
(19/48) Installing libcurl (7.88.1-r0)
(20/48) Installing cfitsio (4.2.0-r0)
(21/48) Installing cgif (0.3.0-r0)
(22/48) Installing libexif (0.6.24-r0)
(23/48) Installing fftw-double-libs (3.3.10-r1)
(24/48) Installing libblkid (2.38.1-r1)
(25/48) Installing libmount (2.38.1-r1)
(26/48) Installing pcre2 (10.42-r0)
(27/48) Installing glib (2.74.6-r0)
(28/48) Installing libimagequant (4.0.4-r0)
(29/48) Installing libjpeg-turbo (2.1.4-r0)
(30/48) Installing lcms2 (2.14-r0)
(31/48) Installing openjpeg (2.5.0-r0)
(32/48) Installing orc (0.4.33-r0)
(33/48) Installing libxft (2.3.7-r0)
(34/48) Installing fribidi (1.0.12-r0)
(35/48) Installing graphite2 (1.3.14-r2)
(36/48) Installing harfbuzz (5.3.1-r1)
(37/48) Installing pango (1.50.13-r0)
(38/48) Installing cairo-gobject (1.17.6-r3)
(39/48) Installing xz-libs (5.2.9-r0)
(40/48) Installing libxml2 (2.10.3-r1)
(41/48) Installing shared-mime-info (2.2-r2)
(42/48) Installing libwebp (1.2.4-r1)
(43/48) Installing zstd-libs (1.5.2-r9)
(44/48) Installing tiff (4.4.0-r1)
(45/48) Installing gdk-pixbuf (2.42.10-r0)
(46/48) Installing librsvg (2.55.1-r0)
(47/48) Installing libspng (0.7.2-r1)
(48/48) Installing vips (8.13.3-r1)
Executing busybox-1.35.0-r29.trigger
Executing shared-mime-info-2.2-r2.trigger
Executing gdk-pixbuf-2.42.10-r0.trigger
OK: 68 MiB in 84 packages
/ # 

You can see there's no libheif in the dependencies, so the vips apk on Alpine does not support HEIC. You'll need to build libvips yourself.

Ah and here too: https://pkgs.alpinelinux.org/package/edge/community/x86_64/vips

It looks like Alpine does not support HEIC or AVIF with libvips, you'll probably need to build libvips yourself.

ok, thank you @jcupitt , i close the issue

miry commented

For people who has the same problem and come to this issue. Here is my solution:

Install the libheif and vips-heif packages to resolve the problem. Here are the installation commands:

Details

/ # apk add libheif
(1/6) Installing aom-libs (3.9.0-r0)
(2/6) Installing libde265 (1.0.15-r0)
(3/6) Installing numactl (2.0.18-r0)
(4/6) Installing x265-libs (3.6-r0)
(5/6) Installing libheif (1.17.6-r1)
(6/6) Installing vips-heif (8.15.2-r1)

/ # gem install ruby-vips
Fetching ruby-vips-2.2.2.gem
Successfully installed ruby-vips-2.2.2
1 gem installed

/ # irb
irb(main):001> require "vips"
=> true
irb(main):002> Vips.get_suffixes
=> 
[".csv",
 ".mat",
 ".raw",
 ".v",
 ".vips",
 ".pbm",
 ".pgm",
 ".ppm",
 ".pfm",
 ".pnm",
 ".hdr",
 ".j2k",
 ".jp2",
 ".jpt",
 ".j2c",
 ".jpc",
 ".gif",
 ".png",
 ".jpg",
 ".jpeg",
 ".jpe",
 ".jfif",
 ".webp",
 ".tif",
 ".tiff",
 ".fits",
 ".fit",
 ".fts",
 ".heic",
 ".heif",
 ".avif"]