Documentation ¶
Index ¶
- Variables
- type Command
- type Image
- type Loader
- type OpCallback
- type OptimiseCmd
- type Processor
- type Queue
- type ResizeCmd
- type Service
- func (r *Service) AsIs(resp http.ResponseWriter, req *http.Request)
- func (r *Service) FitToSizeUrl(resp http.ResponseWriter, req *http.Request)
- func (r *Service) GetRouter() *mux.Router
- func (r *Service) OptimiseUrl(resp http.ResponseWriter, req *http.Request)
- func (r *Service) ResizeUrl(resp http.ResponseWriter, req *http.Request)
Constants ¶
This section is empty.
Variables ¶
var CacheTTL int
Number of seconds that will be written to max-age HTTP header
var Log glogi.Logger = glogi.NewSimpleLogger()
Log writer that can be overrided. Should implement interface glogi.Logger. By default is using glogi.SimpleLogger.
Functions ¶
This section is empty.
Types ¶
type Loader ¶
type Loader interface { // Load loads an image from the given source. // // ctx is a context of the current transaction. Typically it's a context // of an incoming HTTP request, so it's possible to pass values through middlewares. // // Returns an image. Load(src string, ctx context.Context) (*Image, error) }
Loaders is responsible for loading an original image for transformation
type OpCallback ¶
type OpCallback func()
type Processor ¶
type Processor interface { // Resize resizes given image preserving aspect ratio. // Format of the the size argument is width'x'height. // Any dimension could be skipped. // For example: //* 300x200 //* 300 - only width //* x200 - only height Resize(data []byte, size string, imageId string, supportedFormats []string) (*Image, error) // FitToSize resizes given image cropping it to the given size and does not respect aspect ratio. // Format of the the size string is width'x'height, e.g. 300x400. FitToSize(data []byte, size string, imageId string, supportedFormats []string) (*Image, error) // Optimise optimises given image to reduce size of the served image. Optimise(data []byte, imageId string, supportedFormats []string) (*Image, error) }
Processor is an interface for transforming/optimising images.
Each function accepts original image and a list of supported output format by client. Each format should be a MIME type, e.g. image/png, image/webp. The output image will be encoded in one of those formats.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
func (*Queue) AddAndWait ¶
func (q *Queue) AddAndWait(op *Command, callback OpCallback)
type Service ¶
type Service struct { Loader Loader Processor Processor Q []*Queue // contains filtered or unexported fields }
func (*Service) AsIs ¶
func (r *Service) AsIs(resp http.ResponseWriter, req *http.Request)
swagger:operation GET /img/{imgUrl}/asis asisImage
Respond with original image without any modifications ¶
--- tags: - images produces: - image/png - image/jpeg parameters:
- name: imgUrl required: true in: path type: string description: url of the image
responses:
'200': description: Requested image.
func (*Service) FitToSizeUrl ¶
func (r *Service) FitToSizeUrl(resp http.ResponseWriter, req *http.Request)
swagger:operation GET /img/{imgUrl}/fit fitImage
Resize image to the exact size and optimizes it. Will resize image and crop it to the size. If you need to resize image with preserved aspect ratio then use /img/resize endpoint.
--- tags: - images produces: - image/png - image/jpeg parameters:
- name: imgUrl required: true in: path type: string description: url of the original image
- name: size required: true in: query type: string pattern: \d{1,4}x\d{1,4} description: | size of the image in the response. Should be in the format 'width'x'height', e.g. 200x300
responses:
'200': description: Resized image in the same format as original.
func (*Service) OptimiseUrl ¶
func (r *Service) OptimiseUrl(resp http.ResponseWriter, req *http.Request)
swagger:operation GET /img/{imgUrl}/optimise optimiseImage
Optimises image from the given url.
--- tags: - images produces: - image/png - image/jpeg parameters:
- name: imgUrl required: true in: path type: string description: url of the original image
responses:
'200': description: Optimised image in the same format as original.
func (*Service) ResizeUrl ¶
func (r *Service) ResizeUrl(resp http.ResponseWriter, req *http.Request)
swagger:operation GET /img/{imgUrl}/resize resizeImage
Resize image with preserving aspect ratio and optimizes it. If you need the exact size then use /fit operation.
--- tags: - images produces: - image/png - image/jpeg parameters:
- name: imgUrl required: true in: path type: string description: url of the original image
- name: size required: true in: query type: string description: | size of the image in the response. Should be in format 'width'x'height', e.g. 200x300 Only width or height could be passed, e.g 200, x300.
responses:
'200': description: Resized image in the same format as original.