@@ -22,6 +22,7 @@ import (
22
22
"fmt"
23
23
"image"
24
24
"io/ioutil"
25
+ "math"
25
26
"os"
26
27
"os/exec"
27
28
"path"
@@ -239,6 +240,10 @@ func (c *client) createImages(imgs []generateImage) error {
239
240
return imgs [i ].outputPath < imgs [j ].outputPath
240
241
})
241
242
243
+ // Print this before the progress bar is displayed
244
+ workers := int (math .Max (1 , float64 (runtime .NumCPU ())))
245
+ fmt .Printf ("🤖️ Creating %v images using %v workers\n " , len (imgs ), workers )
246
+
242
247
bar := progressbar .NewOptions (
243
248
len (imgs ),
244
249
progressbar .OptionSetRenderBlankState (true ),
@@ -251,7 +256,7 @@ func (c *client) createImages(imgs []generateImage) error {
251
256
jobs := make (chan generateImage , len (imgs ))
252
257
results := make (chan error , len (imgs ))
253
258
254
- for w := 1 ; w <= runtime . NumCPU () ; w ++ {
259
+ for w := 1 ; w <= workers ; w ++ {
255
260
go c .imgCreatorWorker (w , jobs , results )
256
261
}
257
262
@@ -527,7 +532,7 @@ func createAvifImage(img generateImage) error {
527
532
if err != nil {
528
533
return err
529
534
}
530
- defer os .RemoveAll (tmpDir ) // Clean up temporary directory
535
+ defer os .RemoveAll (tmpDir ) // Clean up temporary directory
531
536
532
537
origExt := path .Ext (img .originalPath )
533
538
outputExt := path .Ext (img .outputPath )
@@ -550,7 +555,8 @@ func createAvifImage(img generateImage) error {
550
555
return fmt .Errorf ("failed to created output directory %q: %w" , outputDir , err )
551
556
}
552
557
553
- cmd := exec .Command ("npx" , "avif" , "--input" , tmpPath , "--output" , outputDir , "--overwrite" )
558
+ cmd := exec .Command ("npx" , "avif" , "--input" , tmpFilename , "--output" , outputDir , "--overwrite" )
559
+ cmd .Dir = tmpDir
554
560
output , err := cmd .CombinedOutput ()
555
561
if err != nil {
556
562
fmt .Printf ("Failed to run npx avif: %v\n " , string (output [:]))
0 commit comments