Skip to content

Commit

Permalink
fixup! lottie: add convert function
Browse files Browse the repository at this point in the history
Signed-off-by: Sumner Evans <[email protected]>
  • Loading branch information
sumnerevans committed Jul 10, 2024
1 parent 938ca51 commit 5fb1907
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions lottie/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,46 +39,36 @@ func SetPath(path string) {
// Convert converts lottie data an image or image(s) using lottieconverter.
//
// Args:
// - inputFilename: the filename the lottie file to convert.
// - inputReader: an io.Reader containing the lottie data to convert.
// - input: an io.Reader containing the lottie data to convert.
// - outputFilename: the filename to write the output to.
// - outputWriter: an io.Writer to write the output to.
// - format: the output format. Can be one of: png, gif, or pngs.
// - width: the width of the output image(s).
// - height: the height of the output image(s).
// - extraArgs: additional arguments to pass to lottieconverter.
//
// The inputFilename and inputReader parameters are mutually exclusive.
// The outputFilename and outputWriter parameters are mutually exclusive.
func Convert(ctx context.Context, inputFilename string, inputReader io.Reader, outputFilename string, outputWriter io.Writer, format string, width, height int, extraArgs ...string) error {
func Convert(ctx context.Context, input io.Reader, outputFilename string, outputWriter io.Writer, format string, width, height int, extraArgs ...string) error {
// Verify the input parameters and calculate the actual filenames that will
// be used when shelling out to lottieconverter.
//
// We are panicking here because it's a programming error to call this
// function with invalid parameters.
in := inputFilename
out := outputFilename
if inputFilename == "" && inputReader == nil {
panic("lottie.Convert: either inputFile or inputReader must be provided")
} else if outputFilename == "" && outputWriter == nil {
if outputFilename == "" && outputWriter == nil {
panic("lottie.Convert: either outputFile or outputWriter must be provided")
} else if inputReader != nil {
if inputFilename != "" {
panic("lottie.Convert: only one of inputFile or inputReader can be provided")
}
in = "-"
} else if outputWriter != nil {
if outputFilename != "" {
panic("lottie.Convert: only one of outputFile or outputWriter can be provided")
}
out = "-"
}

args := []string{in, out, format, fmt.Sprintf("%dx%d", width, height)}
args := []string{"-", out, format, fmt.Sprintf("%dx%d", width, height)}
args = append(args, extraArgs...)

cmd := exec.CommandContext(ctx, lottieconverterPath, args...)
cmd.Stdin = inputReader
cmd.Stdin = input
cmd.Stdout = outputWriter
log := zerolog.Ctx(ctx).With().Str("command", "lottieconverter").Logger()
cmd.Stderr = exzerolog.NewLogWriter(log).WithLevel(zerolog.WarnLevel)
Expand Down

0 comments on commit 5fb1907

Please sign in to comment.