libvips icon indicating copy to clipboard operation
libvips copied to clipboard

VipsForeignSave: jfif is not a known file format

Open casperbrike opened this issue 2 years ago • 5 comments

Bug report

Describe the bug I'm using ruby-vips Ruby gem and trying to save an image in JFIF file format, however, it gives me VipsForeignSave error:

img = Vips::Image.new_from_file 'img.jfif'
img.write_to_file 'new-img.jfif' # leads to VipsForeignSave: "new-img.jfif" is not a known file format (Vips::Error)

I debugged this issue a bit and found out that write_to_file calls vips_foreign_find_save function from libvips and vips_foreign_find_save raises VipsForeignSave error for JFIF file format.

Interestingly that libvips does support JFIF format, for example, we can convert JPG image to JFIF and vice versa:

vips jpegsave img.jfif converted.jpg
vips jpegsave converted.jpg converted.jfif

However, if you try to resize a JFIF image then you'll get the same VipsForeignSave error:

vips resize img.jfif resized.jfif 0.5

To Reproduce Steps to reproduce the behavior:

  1. Use Image (GH doesn't allow uploading JFIF files so just remove .txt from filename after you download the image): sun.jfif.txt
  2. Run vips resize sun.jfif resized.jfif 0.5
  3. See VipsForeignSave error

Environment

  • OS: MacOS 13.2
  • Vips: 8.15

Additional details I'm not really proficient at C but, probably, a solution would be to add .jfif here? https://github.com/libvips/libvips/blob/fb94a2ff519c1a94f8f1f765207d11613e4f4b41/libvips/foreign/vips2jpeg.c#L907

casperbrike avatar Dec 08 '23 20:12 casperbrike

Hi @casperbrike,

There are a few things in the saver we'd need to block to write correct JFIF files (eg. CMYK images, EXIF resolution), so just adding the extension probably wouldn't be enough.

I think JFIF shouldn't really be used any more. Are you sure you want to be able to save as JFIF? What's the use case?

jcupitt avatar Dec 09 '23 10:12 jcupitt

Ah I just read the linked issue. I'm amazed that people are still using JFIF!

OK, I'll add .jfif as a suffix for jpeg save, although files saved this way might not be JFIFs, which feels bad.

jcupitt avatar Dec 09 '23 10:12 jcupitt

... this will be in 8.15.1. I credited you in the changelog, I hope that's OK.

jcupitt avatar Dec 09 '23 10:12 jcupitt

Sounds great, thank you very much!

casperbrike avatar Dec 09 '23 11:12 casperbrike

In case anyone runs into this issue using brandoncc's heroku buildpack, I just created a PR to update libvips version on a fork. You can use my fork in case my PR is not merged.

Did some tests on my application and everything looks good

ramses-lopez avatar Feb 08 '24 23:02 ramses-lopez