File tree Expand file tree Collapse file tree 4 files changed +29
-2
lines changed Expand file tree Collapse file tree 4 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ export interface RawImageData<T> {
2
2
width : number ;
3
3
height : number ;
4
4
data : T ;
5
+ comments ?: string [ ] ;
5
6
}
6
7
7
8
type BufferRet = RawImageData < Buffer > ;
@@ -10,7 +11,7 @@ type UintArrRet = RawImageData<Uint8Array>;
10
11
type ImageData = BufferRet | UintArrRet ;
11
12
type BufferLike = Buffer | Uint8Array | ArrayLike < number > | Iterable < number > | ArrayBuffer ;
12
13
13
- export declare function encode ( imgData : RawImageData < BufferLike > , quality ?: number ) : BufferRet ;
14
+ export declare function encode ( imgData : RawImageData < BufferLike > , quality ?: number ) : BufferRet & { comments ?: string [ ] } ;
14
15
15
16
export declare function decode (
16
17
jpegData : BufferLike ,
Original file line number Diff line number Diff line change @@ -797,7 +797,8 @@ function encode(imgData, qu) {
797
797
return {
798
798
data : data ,
799
799
width : imgData . width ,
800
- height : imgData . height
800
+ height : imgData . height ,
801
+ comments : imgData . comments
801
802
} ;
802
803
}
803
804
Original file line number Diff line number Diff line change @@ -179,6 +179,31 @@ it('should be able to create a JPEG from an array', function () {
179
179
expect ( jpegImageData . data ) . toEqual ( expected ) ;
180
180
} ) ;
181
181
182
+ it ( 'should be able to create a JPEG from an array with comment' , function ( ) {
183
+ var width = 320 ,
184
+ height = 180 ;
185
+ var comments = [ "First comment" , "Second comment" ] ;
186
+ var frameData = new Buffer ( width * height * 4 ) ;
187
+ var i = 0 ;
188
+ while ( i < frameData . length ) {
189
+ frameData [ i ++ ] = 0xff ; // red
190
+ frameData [ i ++ ] = 0x00 ; // green
191
+ frameData [ i ++ ] = 0x00 ; // blue
192
+ frameData [ i ++ ] = 0xff ; // alpha - ignored in JPEGs
193
+ }
194
+ var rawImageData = {
195
+ data : frameData ,
196
+ width : width ,
197
+ height : height ,
198
+ comments : comments ,
199
+ } ;
200
+ var jpegImageData = jpeg . encode ( rawImageData , 50 ) ;
201
+ expect ( jpegImageData . width ) . toEqual ( width ) ;
202
+ expect ( jpegImageData . height ) . toEqual ( height ) ;
203
+ var expected = fixture ( 'redbox_comment.jpg' ) ;
204
+ expect ( jpegImageData . data ) . toEqual ( expected ) ;
205
+ } ) ;
206
+
182
207
it ( 'should be able to decode a JPEG into a typed array' , function ( ) {
183
208
var jpegData = fixture ( 'grumpycat.jpg' ) ;
184
209
var rawImageData = jpeg . decode ( jpegData , { useTArray : true } ) ;
You can’t perform that action at this time.
0 commit comments