Graphic Magic如何降低质量

时间:2021-08-28 08:59:39

I am using Graphic Magic to reduce the images

我正在使用Graphic Magic来减少图像

 gm('images/'+local_image_name).resize(223, 147, '^').gravity('Center').crop(223,147).write('images/thumb_'+local_image_name, function (err) {                                                        


});

Here is my code.

这是我的代码。

When i check image properties is is 40-45kb. Also i check youtube thumb images which is of 10-12 kb and very very clear. Can we do it same.

当我检查图像属性是40-45kb。另外,我检查youtube拇指图像,它是10-12 kb,非常非常清晰。我们可以这样做吗?

How? Anyidea ..

怎么样?任何想法 ..

Thanks

谢谢

1 个解决方案

#1


3  

Presumably you can use the quality method:

大概你可以使用质量方法:

image.quality(50).write(filename,function(err){});

See the documentation: http://aheckmann.github.io/gm/docs.html#quality

请参阅文档:http://aheckmann.github.io/gm/docs.html#quality


Additional answer:

From the documentation, it appears that graphics magic implement chainable methods. From you code example I assumed you understood this because your code used it but I may be wrong. The code I wrote above is shorthand for:

从文档中可以看出,图形魔术实现了可链接的方法。从您的代码示例我假设您理解这一点,因为您的代码使用它但我可能是错的。我上面写的代码是简写:

var image = gm('images/'+local_image_name).resize(223, 147, '^').gravity('Center').crop(223,147);
image.quality(50).write(filename,function(err){});

Which can also be written as:

其中也可以写成:

var image = gm('images/'+local_image_name);
image.resize(223, 147, '^');
image.gravity('Center');
image.crop(223,147);
image.quality(50);
image.write(filename,function(err){});

which can also be written as:

也可以写成:

    var image = gm('images/'+local_image_name).resize(223, 147, '^').gravity('Center').crop(223,147).quality(50).write(filename,function(err){});

#1


3  

Presumably you can use the quality method:

大概你可以使用质量方法:

image.quality(50).write(filename,function(err){});

See the documentation: http://aheckmann.github.io/gm/docs.html#quality

请参阅文档:http://aheckmann.github.io/gm/docs.html#quality


Additional answer:

From the documentation, it appears that graphics magic implement chainable methods. From you code example I assumed you understood this because your code used it but I may be wrong. The code I wrote above is shorthand for:

从文档中可以看出,图形魔术实现了可链接的方法。从您的代码示例我假设您理解这一点,因为您的代码使用它但我可能是错的。我上面写的代码是简写:

var image = gm('images/'+local_image_name).resize(223, 147, '^').gravity('Center').crop(223,147);
image.quality(50).write(filename,function(err){});

Which can also be written as:

其中也可以写成:

var image = gm('images/'+local_image_name);
image.resize(223, 147, '^');
image.gravity('Center');
image.crop(223,147);
image.quality(50);
image.write(filename,function(err){});

which can also be written as:

也可以写成:

    var image = gm('images/'+local_image_name).resize(223, 147, '^').gravity('Center').crop(223,147).quality(50).write(filename,function(err){});