File tree 3 files changed +36
-0
lines changed
packages/google-cloud-vision
3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -1269,6 +1269,12 @@ Vision.findImages_ = function(images, callback) {
1269
1269
images = arrify ( images ) ;
1270
1270
1271
1271
function findImage ( image , callback ) {
1272
+ if ( Buffer . isBuffer ( image ) ) {
1273
+ callback ( null , {
1274
+ content : image . toString ( 'base64' )
1275
+ } ) ;
1276
+ return ;
1277
+ }
1272
1278
if ( image instanceof Storage . File ) {
1273
1279
callback ( null , {
1274
1280
source : {
Original file line number Diff line number Diff line change @@ -66,6 +66,20 @@ describe('Vision', function() {
66
66
} ) ;
67
67
} ) ;
68
68
69
+ it ( 'should detect from a Buffer' , function ( done ) {
70
+ var buffer = fs . readFileSync ( IMAGES . logo ) ;
71
+ vision . detect ( buffer , [ 'logos' ] , function ( err , logos ) {
72
+ assert . ifError ( err ) ;
73
+
74
+ var expected = [ 'Google' ] ;
75
+ expected . errors = [ ] ;
76
+
77
+ assert . deepEqual ( logos , expected ) ;
78
+
79
+ done ( ) ;
80
+ } ) ;
81
+ } ) ;
82
+
69
83
describe ( 'single image' , function ( ) {
70
84
var TYPES = [ 'faces' , 'labels' , 'safeSearch' ] ;
71
85
Original file line number Diff line number Diff line change @@ -949,6 +949,22 @@ describe('Vision', function() {
949
949
} ) ;
950
950
} ) ;
951
951
952
+
953
+ it ( 'should get content from a buffer' , function ( done ) {
954
+ var base64String = 'aGVsbG8gd29ybGQ=' ;
955
+ var buffer = new Buffer ( base64String , 'base64' ) ;
956
+
957
+ Vision . findImages_ ( buffer , function ( err , images ) {
958
+ assert . ifError ( err ) ;
959
+ assert . deepEqual ( images , [
960
+ {
961
+ content : base64String
962
+ }
963
+ ] ) ;
964
+ done ( ) ;
965
+ } ) ;
966
+ } ) ;
967
+
952
968
it ( 'should return an error when file cannot be found' , function ( done ) {
953
969
Vision . findImages_ ( './not-real-file.png' , function ( err ) {
954
970
assert . strictEqual ( err . code , 'ENOENT' ) ;
You can’t perform that action at this time.
0 commit comments