使用jimp在Node.js中调整图像大小并获取新图像的路径 [英] Resize an image in Node.js using jimp and get the path the new image

查看:324
本文介绍了使用jimp在Node.js中调整图像大小并获取新图像的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jimp来调整node.js中图像的大小,成功地降低了图像质量,但是有点困惑如何获取新图像的路径

I'm using jimp to resize an image in node.js, I'm successfully able to degrade the image quality, but a bit confused how to get the path of new image

Jimp.read("test.jpg", function (err, test) {
        if (err) throw err;
        test.resize(256, 256)
             .quality(50)                 
             .write("new.jpg"); 
    });

推荐答案

尝试类似的操作

Jimp.read("test.jpg", function (err, test) {
        if (err) throw err;
        test.resize(256, 256)
             .quality(50)                 
             .write(__dirname + "./new.jpg"); 
    });

这应将文件保存到您的项目根目录.

This should save the file to your project root.

有关 __dirname

这篇关于使用jimp在Node.js中调整图像大小并获取新图像的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆