Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package main
import (
"fmt"
"strings"
"strconv"
"errors"
)
func determineImageDimensions(fileName string) (width, height uint64, err error) {
sizeString, err := runProgram1("identify", "-format", "%[fx:w]x%[fx:h]", fmt.Sprintf("%v[0]", fileName))
if err != nil {
return 0, 0, err
}
sizeArr := strings.Split(sizeString, "x")
if len(sizeArr) != 2 {
return 0, 0, errors.New("Can't parse image dimensions")
}
width, err = strconv.ParseUint(sizeArr[0], 10, 64)
if err != nil {
return 0, 0, err
}
height, err = strconv.ParseUint(sizeArr[1], 10, 64)
if err != nil {
return width, 0, err
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.