Skip to content

Commit 53fca43

Browse files
committed
Add NativeImage.ToJPEG
1 parent 549df36 commit 53fca43

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

atom/common/api/atom_api_native_image.cc

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "native_mate/dictionary.h"
1111
#include "native_mate/object_template_builder.h"
1212
#include "ui/gfx/geometry/size.h"
13+
#include "ui/gfx/image/image_util.h"
1314

1415
#include "atom/common/node_includes.h"
1516

@@ -32,6 +33,7 @@ mate::ObjectTemplateBuilder NativeImage::GetObjectTemplateBuilder(
3233
if (template_.IsEmpty())
3334
template_.Reset(isolate, mate::ObjectTemplateBuilder(isolate)
3435
.SetMethod("toPng", &NativeImage::ToPNG)
36+
.SetMethod("toJpeg", &NativeImage::ToJPEG)
3537
.SetMethod("isEmpty", &NativeImage::IsEmpty)
3638
.SetMethod("getSize", &NativeImage::GetSize)
3739
.Build());
@@ -47,6 +49,14 @@ v8::Handle<v8::Value> NativeImage::ToPNG(v8::Isolate* isolate) {
4749
png->size());
4850
}
4951

52+
v8::Handle<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
53+
std::vector<unsigned char> output;
54+
gfx::JPEG1xEncodedDataFromImage(image_, quality, &output);
55+
return node::Buffer::New(isolate,
56+
reinterpret_cast<const char*>(&output.front()),
57+
output.size());
58+
}
59+
5060
bool NativeImage::IsEmpty() {
5161
return image_.IsEmpty();
5262
}

atom/common/api/atom_api_native_image.h

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class NativeImage : public mate::Wrappable {
3232

3333
private:
3434
v8::Handle<v8::Value> ToPNG(v8::Isolate* isolate);
35+
v8::Handle<v8::Value> ToJPEG(v8::Isolate* isolate, int quality);
3536
bool IsEmpty();
3637
gfx::Size GetSize();
3738

0 commit comments

Comments
 (0)