samvera / serverless-iiif

IIIF Image API 2.1 & 3.0 server in an AWS Serverless Application
https://samvera.github.io/serverless-iiif/
Apache License 2.0
69 stars 21 forks source link

Error: VipsJpeg: Bogus JPEG colorspace #112

Closed JoshuaAPhillips closed 1 year ago

JoshuaAPhillips commented 1 year ago

Hello all,

I'm trying to compress my .tif files to slim them down from a bulky ~100mb, and am receiving an error message when trying to access the live files. I'm using ImageMagick to convert the images, with the following command:

for i in *; do 
    convert -density 300 $i -define tiff:tile-geometry=256x256 -compress jpeg -verbose ptif:./output/"$i.tif"; 
    echo "$i converted...";
done

The only thing I've changed since initially generating the images is adding the -compress jpeg flag.

My images convert and compress without a hitch and once uploaded through S3, everything seems fine: the image is viewable through a direct link and the Image API json for a given compressed image is accessible, but the images don't appear in Mirador, etc. and when I try to access the .tif for a compressed image through the server endpoint (i.e., a link like this https://llkn576nqxepo6yucgfh2nl2ea0kkigc.lambda-url.eu-west-2.on.aws/iiif/2/m1-8-1/m1-8-1-1/full/max/0/default.tif) I receive a plaintext error message:

Error: VipsJpeg: Bogus JPEG colorspace
tiff2vips: decompress error tile 0 x 0

The uncompressed images work just fine: I can access them either through a viewer or directly using their URI.

Is this something you can help with?

Thanks, Joshua

mbklein commented 1 year ago

This is a new error to me, but my best guess is that ImageMagick is writing out the TIFFs using RGBA (i.e., with an alpha channel). The TIFF format supports alpha channels, but libtiff's JPEG compressor (which LibVips uses) does not.

Try adding -alpha off to the convert command when you compress the images.

Again, this is just a guess (both the cause and the suggested fix), so I can't guarantee the results, but it's a pretty low effort option to try and see if it works.

JoshuaAPhillips commented 1 year ago

It worked - thank you so much for this!