aws-lambda-image
aws-lambda-image copied to clipboard
Extensible configuration
Am looking for an AWS Lambda solution which would both crop (#38) and resize images, optionally outputting them in an image format different from the input (#45) server-side. Here's a suggestion for an extensible, "command-based" configuration. I have seen similar configuration styles used in internal/proprietary projects.
Note: this might be a crazy idea -- perhaps it's best to just pass all arguments directly to imagemagick?
What do you think?
Benefits
- Can be used to chain/pipe the result from one command (
resize
,crop
,grayscale
etcetera) to one or several other commands (reduce
,save
etcetera). - Commands are easy add to the configuration, using objects
{ "command": "resize", "size": "..." }
. - Subcommands are easy to configure:
{
"command": "grayscale",
"commands": [
{
"command": "flip",
"direction": "horizontal"
},
{
"command": "...",
"commands": [
...
]
}
]
}
- New commands can easily be added, such as conversion to grayscale etcetera.
- Supports per-command-scoped options.
- Commands and options can (should?) be mapped to that of imagemagick, even though it can be rather complex. A shortcut would be to just pass all arguments directly to imagemagick. Might there be a project already doing similar command/option mapping? Needs research.
- Future versions could define "composite commands" (custom commands, macros) which can then be reused:
{
"name": "my-crazy-image-transformation",
"commands": [
{
"command": "rotate",
...
},
{
"command": "draw-text",
...
}
]
}
Drawbacks
- It might be tricky to implement a flexible chaining/piping solution.
- It might be completely overkill for this project.
Example
A simple example showing the input image being saved to two versions, after some commands/transformations.
- The first version has been cropped to 50% of the width and 25% of the height, converted to
image/jpeg
before file size is reduced/optimized and then saved to thefirst-cropped-then-reduced
directory. - The second version was cropped in the same step (thus saving computation time), but then also resized to max 640 by 480 pixels before being saved to the directory
first-cropped-then-resized
as animage/gif
image.
{
"bucket": "your-destination-bucket",
"commands": [
{
"command": "crop",
"gravity": "southeast",
"geometry": "50x25%",
"commands": [
{
"command": "resize",
"geometry": "640x480",
"commands": [
{
"command": "convert",
"type": "image/gif",
"commands": [
{
"command": "save",
"directory": "first-cropped-then-resized"
}
]
}
]
},
{
"command": "convert",
"type": "image/jpeg",
"commands": [
{
"command": "reduce",
"quality": "90",
"commands": [
{
"command": "save",
"directory": "first-cropped-then-reduced"
}
]
}
]
}
]
}
]
}
Commands and options can (should?) be mapped to that of imagemagick, even though it can be rather complex. A shortcut would be to just pass all arguments directly to imagemagick. Might there be a project already doing similar command/option mapping? Needs research.
Rather than having this plugin take on the ownness of mapping n
configurations to any particular series of image processors, perhaps the solution is to just let a user define a series of shells commands to run in series. Perhaps it already exists?
There are plenty of generators and resources online, including man
pages, which can help users derive the resize and convert command-line arguments. I don't see that being a deal breaker for user who only wish to use aws-lambda-sigma (proposed project name)
for image processing. A more generic solution could be more useful to the larger community.