Removed spacial char
parent
d96ad46d45
commit
8ecf4b86ad
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
15
main.go
15
main.go
|
@ -12,15 +12,17 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//ffmpeg -i "tmp/${fName}" -c:v libvpx-vp9 -c:a libopus -s 640x360 -b:v 276k -minrate 138k -maxrate 400k -tile-columns 1 -threads 4 -quality good -crf 36 "tmp/${fName}.webm" 2> /dev/null
|
||||||
|
|
||||||
var finalWidth uint = 1920
|
var finalWidth uint = 1920
|
||||||
var outPath = filepath.Join(".", "out")
|
var outPath = filepath.Join(".", "out")
|
||||||
var inputPath = filepath.Join(".", "assets")
|
var inputPath = filepath.Join(".", "assets")
|
||||||
|
|
||||||
func readArgs() {
|
func readArgs() {
|
||||||
fmt.Println(len(os.Args), os.Args)
|
|
||||||
if len(os.Args) == 4 {
|
if len(os.Args) == 4 {
|
||||||
inputPath = os.Args[1]
|
inputPath = os.Args[1]
|
||||||
outPath = os.Args[2]
|
outPath = os.Args[2]
|
||||||
|
@ -56,6 +58,16 @@ func main() {
|
||||||
|
|
||||||
writeResult(results)
|
writeResult(results)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func removeSpacialCharFromString(src string) string {
|
||||||
|
reg, err := regexp.Compile("[^a-zA-Z0-9-.]+")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("regex err:", err)
|
||||||
|
}
|
||||||
|
processedString := reg.ReplaceAllString(src, "-")
|
||||||
|
return processedString
|
||||||
|
}
|
||||||
|
|
||||||
func handleFile(filePath string, results *[][]string) {
|
func handleFile(filePath string, results *[][]string) {
|
||||||
var individualResult = map[string]string{"fileName": filepath.Base(filePath), "success": "no", "resized": "no", "old": ""}
|
var individualResult = map[string]string{"fileName": filepath.Base(filePath), "success": "no", "resized": "no", "old": ""}
|
||||||
file, err := os.Open(filePath)
|
file, err := os.Open(filePath)
|
||||||
|
@ -110,6 +122,7 @@ func updateResult(results *[][]string, individualResult map[string]string) {
|
||||||
|
|
||||||
func resizeImage(filePath string, file *os.File, img image.Image, individualResult map[string]string) {
|
func resizeImage(filePath string, file *os.File, img image.Image, individualResult map[string]string) {
|
||||||
fileName := filepath.Base(file.Name())
|
fileName := filepath.Base(file.Name())
|
||||||
|
fileName = removeSpacialCharFromString(fileName)
|
||||||
outFileName := outPath + "/" + fileName
|
outFileName := outPath + "/" + fileName
|
||||||
individualResult["old"] = strconv.Itoa(img.Bounds().Dx()) + " x " + strconv.Itoa(img.Bounds().Dy())
|
individualResult["old"] = strconv.Itoa(img.Bounds().Dx()) + " x " + strconv.Itoa(img.Bounds().Dy())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue