node.js - Empty JPEG image (DNL not supported) node-canvas -
i trying use node-canvas crop background image , running weird error following code.
the error "[error: error while writing output stream]". if use crop example code node-canvas repo error "empty jpeg image (dnl not supported)"
/* */ var cnv = new canvas(w,h), ctx = cnv.getcontext('2d'), original = '/img/pages/'+page+'/background.jpg'; ctx.imagesmoothingenabled = true; fs.readfile('public/'+original, function( err,image){ if (err) { res.status(404) .send('not found'); } else { var img = new image; img.src = image; ctx.drawimage(img, math.abs( (w-img.width)/2),0, w,h, 0,0, w,h ); cnv.tobuffer(function(err, buf){ console.log(err); if( err){ res.status(500) .send('error generating image buffer'); } else { fs.writefile('public'+resampled, buf, function(err){ console.log(err); console.log('resized , saved in %dms', new date - start); returnresampledfile( res,page,w,h); }); } }); } }); i've used node-canvas several times no issues reason problem. suggestions great.
libjpeg (which used under hood) doesn't support dnl markers in jpeg files (see document, towards end, explanation). files contains such markers declare of 0 height (hence empty jpeg image message). guess input file uses such markers, triggering error.
as solutions: try , find jpeg reader read these types of files , can convert them libjpeg can handle. i'm afraid can't recommend i've never run problem myself.
Comments
Post a Comment