Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cut down on Processor interface #58

Open
ajatprabha opened this issue Sep 20, 2020 · 0 comments
Open

Cut down on Processor interface #58

ajatprabha opened this issue Sep 20, 2020 · 0 comments

Comments

@ajatprabha
Copy link
Member

What should be cleaned up or changed

Currently, the Processor is getting bulky as we add more operations to it, this creates a problem for implementing new Processor variants as they have to implement all the methods, even if they are out of scope for that processor.

The Processor should have an array of operations that it supports, each Operation can be implemented independently and then the Processor can be composed by selecting these Operations. An RFC document can be prepared to have more clarity on what needs to be changed to achieve this.

Provide any links for context

Ref:

// Processor interface for performing operations on image bytes
type Processor interface {
// Crop takes an image.Image, width, height and a Point and returns the cropped image
Crop(image image.Image, width, height int, point Point) image.Image
// Resize takes an image.Image, width and height and returns the re-sized image
Resize(image image.Image, width, height int) image.Image
// Scale takes an input image, width and height and returns the re-sized
// image without maintaining the original aspect ratio
Scale(image image.Image, width, height int) image.Image
// GrayScale takes an input byte array and returns the grayscaled byte array or error
GrayScale(image image.Image) image.Image
// Blur takes an input byte array and returns the blurred byte array by the specified
// radius(<=1000) or error radius must be larger than 0
Blur(image image.Image, radius float64) image.Image
// Watermark takes an input byte array, overlay byte array and opacity value
// and returns the watermarked image bytes or error
Watermark(base []byte, overlay []byte, opacity uint8) ([]byte, error)
// Flip takes an input image and returns the image flipped. The direction of flip
// is determined by the specified mode - 'v' for a vertical flip, 'h' for a horizontal flip and
// 'vh'(or 'hv') for both.
Flip(image image.Image, mode string) image.Image
// Rotate takes an input image and returns a image rotated by the specified degrees.
// The rotation is applied clockwise, and fractional angles are supported.
Rotate(image image.Image, angle float64) image.Image
// Decode takes a byte array and returns the image, extension, and error
Decode(data []byte) (img image.Image, format string, err error)
// Encode takes an image and extension and return the encoded byte array or error
Encode(img image.Image, format string) ([]byte, error)
// FixOrientation takes an image and it's EXIF orientation (if exist)
// and returns the image with its EXIF orientation fixed
FixOrientation(img image.Image, orientation int) image.Image
// Overlay takes an input byte array as the base image and
// an array of OverlayAttrs to be placed as overlays to the base image
Overlay(base []byte, overlays []*OverlayAttrs) ([]byte, error)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant