使用 imagemagick 将透明 PNG 转换为 JPEG
Convert transparent PNG to JPEG with imagemagick
需要将具有 transparent 背景的 .png 文件转换为具有 .jpeg 的 .jpeg 白色背景。
示例:
const ImageMagick = require('imagemagick');
ImageMagick.convert(
[
'source_file.png',
'destination_file.jpg'
],
function(err, stdout){}
);
结果:目标文件以黑色背景保存。
未找到解决此问题所需的选项。
P.S。 例如 PHP 可以使用 imagecolorallocate() 和 imagefill() 函数来做到这一点。
您可以像这样在 convert
函数中传递参数:
ImageMagick.convert(
[
'source_file.png',
'-background',
'rgb(255,255,255)',
'-flatten',
'destination_file.jpg'
],
function(err, stdout){}
);
在此处查看来源:https://www.npmjs.com/package/imagemagick#convertargs-callbackerr-stdout-stderr
需要将具有 transparent 背景的 .png 文件转换为具有 .jpeg 的 .jpeg 白色背景。
示例:
const ImageMagick = require('imagemagick');
ImageMagick.convert(
[
'source_file.png',
'destination_file.jpg'
],
function(err, stdout){}
);
结果:目标文件以黑色背景保存。
未找到解决此问题所需的选项。
P.S。 例如 PHP 可以使用 imagecolorallocate() 和 imagefill() 函数来做到这一点。
您可以像这样在 convert
函数中传递参数:
ImageMagick.convert(
[
'source_file.png',
'-background',
'rgb(255,255,255)',
'-flatten',
'destination_file.jpg'
],
function(err, stdout){}
);
在此处查看来源:https://www.npmjs.com/package/imagemagick#convertargs-callbackerr-stdout-stderr