Skip to content

Commit

Permalink
Add a fix for new avif cli
Browse files Browse the repository at this point in the history
  • Loading branch information
gauntface committed Dec 13, 2024
1 parent a8c17d1 commit 1551a61
Show file tree
Hide file tree
Showing 2 changed files with 459 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cmds/genimgs/genimgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"image"
"io/ioutil"
"math"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -239,6 +240,10 @@ func (c *client) createImages(imgs []generateImage) error {
return imgs[i].outputPath < imgs[j].outputPath
})

// Print this before the progress bar is displayed
workers := int(math.Max(1, float64(runtime.NumCPU())))
fmt.Printf("🤖️ Creating %v images using %v workers\n", len(imgs), workers)

bar := progressbar.NewOptions(
len(imgs),
progressbar.OptionSetRenderBlankState(true),
Expand All @@ -251,7 +256,7 @@ func (c *client) createImages(imgs []generateImage) error {
jobs := make(chan generateImage, len(imgs))
results := make(chan error, len(imgs))

for w := 1; w <= runtime.NumCPU(); w++ {
for w := 1; w <= workers; w++ {
go c.imgCreatorWorker(w, jobs, results)
}

Expand Down Expand Up @@ -527,7 +532,7 @@ func createAvifImage(img generateImage) error {
if err != nil {
return err
}
defer os.RemoveAll(tmpDir) // Clean up temporary directory
defer os.RemoveAll(tmpDir) // Clean up temporary directory

origExt := path.Ext(img.originalPath)
outputExt := path.Ext(img.outputPath)
Expand All @@ -550,7 +555,8 @@ func createAvifImage(img generateImage) error {
return fmt.Errorf("failed to created output directory %q: %w", outputDir, err)
}

cmd := exec.Command("npx", "avif", "--input", tmpPath, "--output", outputDir, "--overwrite")
cmd := exec.Command("npx", "avif", "--input", tmpFilename, "--output", outputDir, "--overwrite")
cmd.Dir = tmpDir
output, err := cmd.CombinedOutput()
if err != nil {
fmt.Printf("Failed to run npx avif: %v\n", string(output[:]))
Expand Down
Loading

0 comments on commit 1551a61

Please sign in to comment.