feat: inline conversion with status updates, cwebp support, v0.1.4
- Conversion now happens inline on the file list — status column updates from idle → converting... → done/error in place (no separate screen) - Fixed value-receiver bug in convertNext() that prevented 'converting' status from being displayed - Added cwebp fallback for PNG/JPEG → WebP (ffmpeg webp encoder often missing on macOS) - Format selector arrows hidden during conversion/results states - Simplified to 2 states: stateFileList + stateResults - Added tests for conversion state machine and view rendering
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package converter
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConvertImage(t *testing.T) {
|
||||
// Find a test PNG file
|
||||
testFile := filepath.Join("..", "..", "..", "public", "logo.png")
|
||||
if _, err := os.Stat(testFile); err != nil {
|
||||
t.Skipf("test file not found: %s", testFile)
|
||||
}
|
||||
|
||||
outDir := t.TempDir()
|
||||
result := Convert(testFile, "webp", outDir)
|
||||
if result.Err != nil {
|
||||
t.Fatalf("conversion failed: %v", result.Err)
|
||||
}
|
||||
|
||||
info, err := os.Stat(result.OutputPath)
|
||||
if err != nil {
|
||||
t.Fatalf("output file not found: %v", err)
|
||||
}
|
||||
|
||||
t.Logf("Converted %s -> %s (%d bytes)", testFile, result.OutputPath, info.Size())
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/image/bmp"
|
||||
@@ -88,6 +89,17 @@ func tryDecodeImage(f *os.File, path string) (image.Image, error) {
|
||||
}
|
||||
|
||||
func convertImageViaFFmpeg(inputPath, outputPath, format string) error {
|
||||
// For WebP: prefer cwebp (from libwebp-tools) which is widely available
|
||||
if format == "webp" {
|
||||
if cwebpPath, err := exec.LookPath("cwebp"); err == nil {
|
||||
cmd := exec.Command(cwebpPath, "-q", "90", inputPath, "-o", outputPath)
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("cwebp error: %w\n%s", err, string(out))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
args := []string{"-y", "-i", inputPath}
|
||||
|
||||
switch format {
|
||||
|
||||
Reference in New Issue
Block a user