I'm attempting to build a cloud function written in Go, that will use the available ImageMagick library in Google's Cloud Functions infrastructure to composite & manipulate several images into a resulting output image.
The root of the problem, is that the ImageMagick function that I want to use is available, but it takes multiple distinct inputs in order to work. My inputs are objects in a Storage Bucket.
The os/exec Cmd struct allows you to do this, by using an "ExtraFiles" array, and I know how to provide these extra files to my ImageMagick command.
However, the "ExtraFiles" array only wants to store instances of os.File, whereas the GCP Storage Client gives you a "Reader" instance when you open a file.
backgroundBlob := storageClient.Bucket(inputBucket).Object(background)
backgroundImg, err := backgroundBlob.NewReader(ctx)
if err != nil {
return "", fmt.Errorf("backgroundImg: %v", err)
}
foregroundBlob := storageClient.Bucket(inputBucket).Object(foreground)
foregroundImg, err := foregroundBlob.NewReader(ctx)
if err != nil {
return "", fmt.Errorf("foregroundImg: %v", err)
}
outputBlob := storageClient.Bucket(outputBucket).Object(output)
outputImg := outputBlob.NewWriter(ctx)
defer outputImg.Close()
// Set up some additional file handles since we're dealing with more inputs than STDIN Can cope with
cmd := exec.Command("convert", "fd:3", "fd:4", "-composite", "fd:5")
cmd.ExtraFiles = append(cmd.ExtraFiles,backgroundImg)
cmd.ExtraFiles = append(cmd.ExtraFiles,foregroundImg)
cmd.ExtraFiles = append(cmd.ExtraFiles,outputImg)
if err := cmd.Run(); err != nil {
return "", fmt.Errorf("cmd.Run: %v", err)
}
log.Printf("Blurred image has been uploaded to %s", outputBlob.ObjectName())
return outputBlob.ObjectName(), nil
}```
So, from where I am at the moment, I need to do one of the following two things:
1. Figure out how to get Google's storage API to treat/use objects in their storage buckets as "os.File"s
OR
2. Figure out how to execute my "convert" command using multiple Readers as input, rather than leveraging the ExtraFiles array.
If anybody out there has any ideas on how to achieve either of the above, or has alternate ways of solving this problem, I would be very grateful to hear them!