Last active
January 12, 2019 12:13
-
-
Save ivanzoid/e52f8b575a2cd924e6c5a54c845e8308 to your computer and use it in GitHub Desktop.
This file contains hidden or 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