bubblydoo/librsvg-lambda-layer

"could not load image: Unrecognized image file format" using inline jpeg

Closed this issue ยท 4 comments

Hi, I'm using rsvg-convert to build a PDF from an SVG file. Following Caveats section, I'm using data:// for images. Everything work as expected with png files but jpeg are not included.

After enabling rsvg-convert log I see the following on stdout

could not load image "data:image/jpeg;base64,.......": Unrecognized image file format

I wrote a small lambda function to reproduce the behavior librsvg-pdf-example.zip.

The lambda calls rsvg-convert and returns the pdf file encoded with base64. The input is cloud-jpeg.svg or cloud-png.svg depending on lambda arguments. These files are copies of cloud.svg with the path filled with black instead of white.

I'm using docker to simulate a lambda environment.

The following generates output-png.pdf file with the expected result.

docker run --rm -v "$PWD":/var/task:ro,delegated -v "$PWD"/librsvg-lambda-layer:/opt:ro,delegated lambci/lambda:nodejs12.x index.handler '{ "mime": "png" }' | cut -d "\"" -f 2 | base64 -d > output-png.pdf

but the following produces a pdf without background

docker run --rm -v "$PWD":/var/task:ro,delegated -v "$PWD"/librsvg-lambda-layer:/opt:ro,delegated lambci/lambda:nodejs12.x index.handler '{ "mime": "jpeg" }' | cut -d "\"" -f 2 | base64 -d > output-jpeg.pdf

Could be that the builtin jpeg loader is not working?

Any help would be appreciated.

Hi, thanks for raising this issue. I haven't really tested it with JPEGs but I assumed they would work. I can reproduce your issue. I think this has something to do with the GDK pixbuf loaders and maybe this line:

--disable-pixbuf-loader \

or this line where the /opt/lib/gdk-pixbuf-loaders.cache file is removed:
rm -r /opt/lib && rm -r /opt/include && rm /opt/bin/gdk-pixbuf-query-loaders

I forgot why I did these exact things but I assume doing it any other way didn't work when trying to build a statically linked binary for Rsvg. I'm still not sure if it's possible to statically link a loader. I'll try to re-enable some things and I'll let you know how it goes.

In the meanwhile you can use a library like sharp to convert the jpegs to pngs (coincidentally I also made a Lambda layer for that ๐Ÿ™‚: https://github.com/bubblydoo/lambda-layer-sharp)

Thanks for taking the time to look into this and for the sharp suggestion.

I ended up using an old version of rsvg-convert (2.26.3). I was using it and found a bug with some SVGs conversions (not related to this issue). The bug is not present in newer versions. Upgrade rsvg-convert was my motivation to use your layer.

I found a workaround to the original problem ๐Ÿ™‚. Using an old version is not ideal but works better for me than adding an extra conversion step.

Hi @mgrunberg, I took another look at the issue, and it seems to work with the latest release! I'll close this issue for now.