File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @tidaltheory/lens ' : minor
3
+ ---
4
+
5
+ ` jpg ` command to convert an image to a high-quality JPG file
Original file line number Diff line number Diff line change @@ -144,4 +144,30 @@ prog.command('add <src>')
144
144
}
145
145
} )
146
146
147
+ prog . command ( 'jpg <src>' )
148
+ . describe ( 'Convert an image to high-quality JPG' )
149
+ . action ( async ( source : string ) => {
150
+ let spinner = ora ( ) . start ( )
151
+ let { name, ext } = parse ( source )
152
+
153
+ if ( ext . endsWith ( 'jpg' ) ) {
154
+ spinner . succeed ( 'Image is already in JPG format!' )
155
+ // eslint-disable-next-line unicorn/no-process-exit
156
+ process . exit ( 0 )
157
+ }
158
+
159
+ let sharpImage = sharp ( source )
160
+ spinner . text = 'Converting to JPG...'
161
+
162
+ try {
163
+ await sharpImage
164
+ . withMetadata ( )
165
+ . toFormat ( 'jpg' , { quality : 100 , chromaSubsampling : '4:4:4' } )
166
+ . toFile ( `${ name } .jpg` )
167
+ spinner . succeed ( `${ name } converted to JPG format!` )
168
+ } catch ( error : unknown ) {
169
+ spinner . fail ( String ( error ) )
170
+ }
171
+ } )
172
+
147
173
prog . parse ( process . argv )
You can’t perform that action at this time.
0 commit comments