This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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