node-mapnik icon indicating copy to clipboard operation
node-mapnik copied to clipboard

renderFile format options

Open jonshutt opened this issue 5 years ago • 4 comments

Hi, I'm rendering a bunch of files, but struggling with the format option

map.renderFile(filePath, { format: format }, (err) => { ... }

Eg, format = webp:quality=90 outputs the same file sizes as webp:quality=30, and jpg outputs the same as jpg30 as jpg90.

I'm referencing https://github.com/mapnik/mapnik/wiki/Image-IO to write the formatting options.

Is there something I'm missing?

jonshutt avatar Aug 24 '20 07:08 jonshutt

@jonshutt - your syntax looks fine to me ^ I'm not familiar with all webp options. This can be mapnik core issue or node-mapnik - I'll find time to debug this issue. Could you post details about your setup - mapnik/node-mapnik versions etc, thanks

artemp avatar Aug 24 '20 15:08 artemp

@jonshutt - ok, I see what's wrong: renderFile (async) expects image_format option while renderFileSync expects format. Looks like a bug/typo to me. As a quick workaround you should be able to :

map.renderFile(filePath, { image_format: "webp:quality=30" }, (err) => { ... }

artemp avatar Aug 26 '20 10:08 artemp

@artemp I just gave that go - but it still didn't seem to make any difference. I did however do a bit more reading, and changed from renderFile to the following, which worked fine and the file quality/size is definitely picking the different formatting options

var im = new mapnik.Image(256, 256);
map.render(im, (err, im) => {
   if (err) throw err;
   im.save(filePath,  "webp:quality=30"); 
}

jonshuttsnap40 avatar Aug 26 '20 14:08 jonshuttsnap40

@jonshutt :+1:

artemp avatar Aug 26 '20 14:08 artemp