Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions shell.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
)

func main() {
// array for base filenames
var base_names []string

// change into image directory
err := os.Chdir("image_batch")

// get all png files
files, err := filepath.Glob("*.png")

// create an array of base filenames
for _, file := range files {
var name = file[0:len(file)-len(filepath.Ext(file))]
base_names = append(base_names, name)
}

// convert each png image to jpg
for _, name := range base_names {
cmd := "convert"
args := []string{fmt.Sprintf("%s.png", name), fmt.Sprintf("%s.jpg", name)}
if err := exec.Command(cmd, args...).Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Printf("Successfully converted %s.png to jpg\n", name)
}

if err != nil {
log.Fatal(err)
}

// print filenames
fmt.Println(filepath.Glob("*.png"))
}