0

I'm currently using ImageMagick and gm to process images from a buffer. My problem is that I cannot control what file types are put in the buffer but wish to have everything turned to jpg.

Not sure how to do that using the buffer since I'm not giving it an output file path with extension.

gm(buf).command('convert').in('-auto-orient','-resize','500x','-quality','92','-strip','-quality','100','jpg').toBuffer((err, buffer) => err ? reject(err) : resolve(buffer));
Smit Gajera
  • 1,001
  • 1
  • 8
  • 26

1 Answers1

0

I don't know anything about the node.js bindings of ImageMagick or GraphicsMagick, but I do know that if you do this in Terminal, you will force a JPEG output, so maybe you can adapt that...

# Make a 1x1 black image and write to stdout as JPEG. Dump result with 'xxd'
gm convert xc:black jpg:- | xxd

00000000: ffd8 ffe0 0010 4a46 4946 0001 0101 0048  ......JFIF.....H
00000010: 0048 0000 ffdb 0043 0008 0606 0706 0508  .H.....C........
00000020: 0707 0709 0908 0a0c 140d 0c0b 0b0c 1912  ................
00000030: 130f 141d 1a1f 1e1d 1a1c 1c20 242e 2720  ........... $.' 
00000040: 222c 231c 1c28 3729 2c30 3134 3434 1f27  ",#..(7),01444.'
00000050: 393d 3832 3c2e 3334 32ff c000 0b08 0001  9=82<.342.......
00000060: 0001 0101 1100 ffc4 0014 0001 0000 0000  ................
00000070: 0000 0000 0000 0000 0000 0008 ffc4 0014  ................
00000080: 1001 0000 0000 0000 0000 0000 0000 0000  ................
00000090: 0000 ffda 0008 0101 0000 3f00 3fbf ffd9  ..........?.?...

It is just the same with ImageMagick and, say, PNG output:

magick xc:black png:-
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432