简体   繁体   中英

How to convert image from png to jpg in jimp?

I read the docs: https://github.com/oliver-moran/jimp

But could not find how to convert an image from png to jpg.

I must have missed something obvious.

Using jimp on my server with Node.js.

Here's my code:

image.scaleToFit(500, 500, Jimp.RESIZE_BICUBIC).quality(60).write("./public/images/uploads/thumb"+req.file.filename, function(err) {

What is wrong with the example from their documentation? It kind of does what you want - converts png to jpg.

var Jimp = require("jimp");

// open a file called "lenna.png"
Jimp.read("lenna.png", function (err, lenna) {
    if (err) throw err;
    lenna.resize(256, 256)            // resize
         .quality(60)                 // set JPEG quality
         .greyscale()                 // set greyscale
         .write("lena-small-bw.jpg"); // save
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM