Open FelipeGerolomo opened 5 years ago
Hi Felipe,
Sorry for the delayed response. It looks like you are reading from the stream twice, which doesn't work. I'd suggest you first read the file into a buffer and then resize it. See https://www.npmjs.com/package/concat-stream for an example.
Cheers, Jonas
Hi Wagner, I meet the problem which tips "{ Error: read ECONNRESET at TLSWrap.onStreamRead (internal/stream_base_commons.js:111:27) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }" Well , I copied your example as the wiki writes.
`var express = require('express'); var router = express.Router(); var uploads = require('./upload'); var request = require('request'); var gm = require('gm').subClass({ imageMagick: true }); var smartcrop = require('smartcrop-gm');
var src = 'https://raw.githubusercontent.com/jwagner/smartcrop-gm/master/test/flower.jpg'; applySmartCrop(src, 'public/images/', 300, 300);
function applySmartCrop(src, dest, width, height) { request(src, { encoding: null }, function process(error, response, body) { //if (error) return console.error(error);
smartcrop.crop(body, { width: 100, height: 100 }).then((err, result) => { var crop = result.topCrop; gm(body) .crop(crop.width, crop.height, crop.x, crop.y) .resize(width, height) .write(dest, function(error) { if (error) return console.error(error); }); }).catch(error => { console.log("erro", error) }) }); }
module.exports = router;
OUTPUT: { Error: write EOF at WriteWrap.afterWrite [as oncomplete] (net.js:788:14) errno: 'EOF', code: 'EOF', syscall: 'write' }`