How to use the jimp.AUTO function in jimp

To help you get started, we’ve selected a few jimp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wesbos / Learn-Node / stepped-solutions / 36 / controllers / storeController.js View on Github external
exports.resize = async (req, res, next) => {
  // check if there is no new file to resize
  if (!req.file) {
    next(); // skip to the next middleware
    return;
  }
  const extension = req.file.mimetype.split('/')[1];
  req.body.photo = `${uuid.v4()}.${extension}`;
  // now we resize
  const photo = await jimp.read(req.file.buffer);
  await photo.resize(800, jimp.AUTO);
  await photo.write(`./public/uploads/${req.body.photo}`);
  // once we have written the photo to our filesystem, keep going!
  next();
};
github afuh / pinstagram / controllers / imageControllers.js View on Github external
exports.resize = async (req, res, next) => {
  if (req.body.caption && req.body.caption.length > 140) {
    req.flash('error', 'Upload failed, apparently you have written too much')
    return res.redirect('back')
  }
  //rename
  const extension = req.file.mimetype.split('/')[1];
  req.body.url = crypto.randomBytes(10).toString('hex');
  req.body.photo = `${req.body.url}.${extension}`;

  // resize
  const photo = await jimp.read(req.file.buffer);
  await photo.resize(600, jimp.AUTO).quality(70);
  await photo.write(`./public/uploads/${req.body.photo}`);

  await photo.cover(290, 290, jimp.HORIZONTAL_ALIGN_CENTER | jimp.VERTICAL_ALIGN_MIDDLE);
  await photo.write(`./public/uploads/gallery/${req.body.photo}`);

  next();
}
github herrstucki / responsive-loader / src / adapters / jimp.js View on Github external
readImage.then(image => {
          image.clone()
            .resize(width, jimp.AUTO)
            .quality(options.quality)
            .background(parseInt(options.background, 16) || 0xFFFFFFFF)
            .getBuffer(mime, function(err, data) { // eslint-disable-line func-names
              if (err) {
                reject(err);
              } else {
                resolve({
                  data,
                  width,
                  height: this.bitmap.height
                });
              }
            });
        });
      })
github NetsBlox / NetsBlox / src / server / routes / projects.js View on Github external
.then(image => {
            var width = image.bitmap.width,
                height = image.bitmap.height,
                pad = Utils.computeAspectRatioPadding(width, height, ratio);
            // round paddings to behave like lwip
            let wDiff = parseInt((2*pad.left));
            let hDiff = parseInt((2*pad.top));
            image = image.contain(width + wDiff, height + hDiff);
            return Q.ninvoke(image, 'getBuffer', Jimp.AUTO);
        });
};
github AndrusAsumets / react-lazy-blur / scripts / lazy.js View on Github external
const process = async function(i) {
	if(i < files.length ) {
		const file = files[i]
		const regex = /\.(jpe?g||png)$/
		
		if (
			regex.test(file) == false ||
			file.includes('.lazy') || 
			file.includes('.blur')
		) return process(i + 1)
		
		console.log('Lazying:', folder + file)
		const image = await Jimp.read(folder + file).catch((err) => { return console.log(err) })
		image.resize(1280, Jimp.AUTO)
		image.quality(90)
		
		const prefix = file.split(regex)[0]
		const suffix = file.split(regex)[1]
		const saveName = prefix + '.lazy.' + suffix
		const save = await image.write(folder + saveName)
		
		process(i + 1)
	}
}
process(0)
github QTGate / QTGate-Desktop-Client / app / tools / uploadFile.js View on Github external
return Jimp.read(_media, (err, image) => {
        if (err) {
            return CallBack(err);
        }
        const uu = image.bitmap;
        if (uu.height > uu.width) {
            image.resize(Jimp.AUTO, imageMaxHeight);
        }
        else {
            image.resize(imageMaxWidth, Jimp.AUTO);
        }
        if (/\/PNG/i.test(type)) {
            return image.deflateStrategy(1, () => {
                return exportImage(type, image);
            });
        }
        if (/\/(JPEG|JPG)/i.test(type)) {
            return image.quality(100, () => {
                return exportImage(type, image);
            });
        }
        //		BMP and all other to PNG
        ret.media_type = 'image/png';
        return image.deflateStrategy(4, () => {
            return exportImage(ret.media_type, image);
        });
github GetPublii / Publii / app / back-end / image.js View on Github external
Jimp.read(originalPath, function (err, image) {
                            if (err) {
                                reject(err);
                            }

                            console.log('JIMP COVER', finalWidth, ' x ', finalHeight);

                            if (finalWidth === Jimp.AUTO || finalHeight === Jimp.AUTO) {
                                image.resize(finalWidth, finalHeight)
                                     .quality(imagesQuality)
                                     .write(destinationPath, function() {
                                         resolve(destinationPath);
                                     });
                            } else {
                                image.cover(finalWidth, finalHeight)
                                     .quality(imagesQuality)
                                     .write(destinationPath, function() {
                                         resolve(destinationPath);
                                     });
                            }
                        }).catch(err => {
                            console.log(err);
github QTGate / QTGate-Desktop-Client / app / twitter.ts View on Github external
return Jimp.read ( _media, ( err, image ) => {
				if ( err ) {
					return CallBack ( err )
				}
				const uu = image.bitmap
				if ( uu.height > uu.width ) {
					image.resize ( Jimp.AUTO, tweetImageMaxHeight )
				} else {
					image.resize ( tweetImageMaxWidth, Jimp.AUTO )
				}
				if ( /\/PNG/i.test ( type )) {
					return image.deflateStrategy ( 1, () => {
						return exportImage ( type, image )
					})
				}
				if ( /\/(JPEG|JPG)/i.test ( type )) {
					return image.quality ( 100, () => {
						return exportImage ( type, image )
					})
				}
				//		BMP and all other to PNG
				ret.media_type = 'image/png'
				return image.deflateStrategy ( 4, () => {
github qlik-oss / after-work.js / plugins / chai-plugin-screenshot / src / index.js View on Github external
        const fn = (resolve, reject) => (input.img ? input.img : input).getBuffer(jimp.AUTO, (e, b) => (e ? reject(e) : resolve(b)));
        return new Promise(fn).then(buffer => jimp.read(buffer));
github SideProjectGuys / invite-manager-bot / src / example / qr.ts View on Github external
function resizeSquared(img: Jimp, _w: number, _h: number) {
	let w;
	let h;

	if (_h > _w) {
		w = Jimp.AUTO;
		h = _h;
	} else {
		w = _w;
		h = Jimp.AUTO;
	}
	return img.resize(w, h);
}