diff --git a/cmd/docgen/main.go b/cmd/docgen/main.go index 4ee0b35..a519ce2 100644 --- a/cmd/docgen/main.go +++ b/cmd/docgen/main.go @@ -18,14 +18,15 @@ import ( "github.com/stoewer/go-strcase" ) -func saveMeta(service, readme, openapijson string) error { +func saveMeta(service, readme, openapijson, examplejson string) error { client := &http.Client{} //Encode the data postBody, _ := json.Marshal(map[string]string{ - "serviceName": service, - "readme": readme, - "openAPIJSON": openapijson, + "serviceName": service, + "readme": readme, + "openAPIJSON": openapijson, + "examplesJSON": examplejson, }) rbody := bytes.NewBuffer(postBody) @@ -122,7 +123,10 @@ func main() { os.Exit(1) } - err = saveMeta(serviceName, string(dat), string(js)) + // not every service has examples + examples, _ := ioutil.ReadFile(filepath.Join(serviceDir, "examples.json")) + + err = saveMeta(serviceName, string(dat), string(js), string(examples)) if err != nil { fmt.Println("Failed to save meta to explore service", err) os.Exit(1) diff --git a/go.mod b/go.mod index 4d7793e..39b9db2 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/Masterminds/semver/v3 v3.1.1 github.com/PuerkitoBio/goquery v1.6.1 github.com/SlyMarbo/rss v1.0.1 + github.com/disintegration/imaging v1.6.2 github.com/getkin/kin-openapi v0.26.0 github.com/gojuno/go.osrm v0.1.1-0.20200217151037-435fc3e1d3d4 github.com/golang/protobuf v1.5.1 diff --git a/go.sum b/go.sum index ebbd7ad..2fee257 100644 --- a/go.sum +++ b/go.sum @@ -115,6 +115,8 @@ github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f/go.mod h1:xH/i4TFM github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= +github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= +github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= github.com/dnaeon/go-vcr v0.0.0-20180814043457-aafff18a5cc2/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E= github.com/dnsimple/dnsimple-go v0.30.0/go.mod h1:O5TJ0/U6r7AfT8niYNlmohpLbCSG+c71tQlGr9SeGrg= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= @@ -619,6 +621,8 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 h1:hVwzHzIUGRjiF7EcUjqNxk3NCfkPxbDKRdnNE1Rpg0U= +golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= diff --git a/image/.gitignore b/image/.gitignore new file mode 100644 index 0000000..f4dfa81 --- /dev/null +++ b/image/.gitignore @@ -0,0 +1,2 @@ + +image diff --git a/image/Dockerfile b/image/Dockerfile new file mode 100644 index 0000000..0d03f0b --- /dev/null +++ b/image/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine +ADD image /image +ENTRYPOINT [ "/image" ] diff --git a/image/Makefile b/image/Makefile new file mode 100644 index 0000000..8c0e197 --- /dev/null +++ b/image/Makefile @@ -0,0 +1,26 @@ + +GOPATH:=$(shell go env GOPATH) +.PHONY: init +init: + go get -u github.com/golang/protobuf/proto + go get -u github.com/golang/protobuf/protoc-gen-go + go get github.com/micro/micro/v3/cmd/protoc-gen-micro +.PHONY: proto +proto: + protoc --openapi_out=. --proto_path=. --micro_out=. --go_out=. proto/image.proto + +docs: + protoc --openapi_out=. --proto_path=. --micro_out=. --go_out=. proto/image.proto + @redoc-cli bundle api-image.json + +.PHONY: build +build: + go build -o image *.go + +.PHONY: test +test: + go test -v ./... -cover + +.PHONY: docker +docker: + docker build . -t image:latest diff --git a/image/README.md b/image/README.md new file mode 100644 index 0000000..9c3ad73 --- /dev/null +++ b/image/README.md @@ -0,0 +1,23 @@ +# Image Service + +This is the Image service + +Generated with + +``` +micro new image +``` + +## Usage + +Generate the proto code + +``` +make proto +``` + +Run the service + +``` +micro run . +``` \ No newline at end of file diff --git a/image/examples.json b/image/examples.json new file mode 100644 index 0000000..dde463d --- /dev/null +++ b/image/examples.json @@ -0,0 +1,27 @@ +{ + "resize": [{ + "title": "Base64 to hosted image", + "description": "Resize an input base64 encoded image and store the resulting resized image on our CDN.", + "request": { + "base64": "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==", + "outputURL": true, + "imageID": "cat.png", + "width": 100, + "height": 100 + }, + "response": { + "url": "cdn.images.m3o.com/your-account-id/cat.png" + } + }, { + "title": "Base64 to base64 image", + "description": "Resize a base64 encoded image on the fly without storing it anywhere", + "request": { + "base64": "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==", + "width": 100, + "height": 100 + }, + "response": { + "base64": "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" + } + }] +} \ No newline at end of file diff --git a/image/generate.go b/image/generate.go new file mode 100644 index 0000000..96f431a --- /dev/null +++ b/image/generate.go @@ -0,0 +1,2 @@ +package main +//go:generate make proto diff --git a/image/handler/image.go b/image/handler/image.go new file mode 100644 index 0000000..5612a69 --- /dev/null +++ b/image/handler/image.go @@ -0,0 +1,209 @@ +package handler + +import ( + "bytes" + "context" + "encoding/base64" + "errors" + "fmt" + "image" + "image/jpeg" + "image/png" + "net/http" + "strings" + + "github.com/disintegration/imaging" + "github.com/micro/micro/v3/service/config" + "github.com/micro/micro/v3/service/store" + img "github.com/micro/services/image/proto" + "github.com/micro/services/pkg/tenant" +) + +const pathPrefix = "images" +const hostPrefix = "https://micro-store-bucket-125b9f0.ams3.cdn.digitaloceanspaces.com" + +type Image struct { + hostPrefix string +} + +func NewImage() *Image { + var hp string + cfg, err := config.Get("micro.image.host_prefix") + if err != nil { + hp = cfg.String(hostPrefix) + } + if len(hp) == 0 { + hp = hostPrefix + } + return &Image{ + hostPrefix: hp, + } +} + +func (e *Image) Upload(ctx context.Context, req *img.UploadRequest, rsp *img.UploadResponse) error { + tenantID, ok := tenant.FromContext(ctx) + if !ok { + return errors.New("Not authorized") + } + var srcImage image.Image + var err error + if len(req.Base64) > 0 { + srcImage, err = base64ToImage(req.Base64) + if err != nil { + return err + } + } else { + response, err := http.Get(req.Url) + if err != nil { + return err + } + switch { + case strings.HasSuffix(req.Url, ".png"): + srcImage, err = png.Decode(response.Body) + case strings.HasSuffix(req.Url, ".jpg") || strings.HasSuffix(req.Url, ".jpeg"): + srcImage, err = jpeg.Decode(response.Body) + } + if err != nil { + return err + } + defer response.Body.Close() + } + buf := new(bytes.Buffer) + err = jpeg.Encode(buf, srcImage, nil) + if err != nil { + return err + } + + err = store.DefaultBlobStore.Write(fmt.Sprintf("%v/%v/%v", pathPrefix, tenantID, req.ImageID), buf) + if err != nil { + return err + } + rsp.Url = fmt.Sprintf("%v/%v/%v/%v/%v", e.hostPrefix, "micro", "images", tenantID, req.ImageID) + return nil +} + +func base64ToImage(b64 string) (image.Image, error) { + var srcImage image.Image + res := []byte{} + _, err := base64.StdEncoding.Decode([]byte(strings.Split(b64, ",")[1]), res) + if err != nil { + return srcImage, err + } + switch { + case strings.HasPrefix("data:image/png", b64): + srcImage, err = png.Decode(bytes.NewReader(res)) + case strings.HasPrefix("data:image/jpg", b64) || strings.HasPrefix("data:image/jpeg", b64): + srcImage, err = jpeg.Decode(bytes.NewReader(res)) + } + return srcImage, nil +} + +func (e *Image) Resize(ctx context.Context, req *img.ResizeRequest, rsp *img.ResizeResponse) error { + tenantID, ok := tenant.FromContext(ctx) + if !ok { + return errors.New("Not authorized") + } + var srcImage image.Image + var err error + if len(req.Base64) > 0 { + srcImage, err = base64ToImage(req.Base64) + if err != nil { + return err + } + } else { + response, err := http.Get(req.Url) + if err != nil { + return err + } + switch { + case strings.HasSuffix(req.Url, ".png"): + srcImage, err = png.Decode(response.Body) + case strings.HasSuffix(req.Url, ".jpg") || strings.HasSuffix(req.Url, ".jpeg"): + srcImage, err = jpeg.Decode(response.Body) + } + if err != nil { + return err + } + defer response.Body.Close() + } + resultImage := imaging.Resize(srcImage, int(req.Width), int(req.Height), imaging.Lanczos) + buf := new(bytes.Buffer) + switch { + case strings.HasSuffix(req.ImageID, ".png"): + err = png.Encode(buf, resultImage) + case strings.HasSuffix(req.ImageID, ".jpg") || strings.HasSuffix(req.Url, ".jpeg"): + err = jpeg.Encode(buf, resultImage, nil) + } + + if err != nil { + return err + } + if req.OutputURL { + err = store.DefaultBlobStore.Write(fmt.Sprintf("%v/%v/%v", pathPrefix, tenantID, req.ImageID), buf) + if err != nil { + return err + } + rsp.Url = fmt.Sprintf("%v/%v/%v/%v/%v", e.hostPrefix, "micro", "images", tenantID, req.ImageID) + } else { + dst := []byte{} + base64.StdEncoding.Encode(dst, buf.Bytes()) + rsp.Base64 = string(dst) + return nil + } + return nil +} + +func (e *Image) Convert(ctx context.Context, req *img.ConvertRequest, rsp *img.ConvertResponse) error { + tenantID, ok := tenant.FromContext(ctx) + if !ok { + return errors.New("Not authorized") + } + var srcImage image.Image + var err error + if len(req.Base64) > 0 { + srcImage, err = base64ToImage(req.Base64) + if err != nil { + return err + } + } else { + response, err := http.Get(req.Url) + if err != nil { + return err + } + switch { + case strings.HasSuffix(req.Url, ".png"): + srcImage, err = png.Decode(response.Body) + case strings.HasSuffix(req.Url, ".jpg") || strings.HasSuffix(req.Url, ".jpeg"): + srcImage, err = jpeg.Decode(response.Body) + } + if err != nil { + return err + } + defer response.Body.Close() + } + + buf := new(bytes.Buffer) + switch { + case strings.HasSuffix(req.ImageID, ".png"): + err = png.Encode(buf, srcImage) + case strings.HasSuffix(req.ImageID, ".jpg") || strings.HasSuffix(req.Url, ".jpeg"): + err = jpeg.Encode(buf, srcImage, nil) + } + + if err != nil { + return err + } + if req.OutputURL { + err = store.DefaultBlobStore.Write(fmt.Sprintf("%v/%v/%v", pathPrefix, tenantID, req.ImageID), buf) + if err != nil { + return err + } + rsp.Url = fmt.Sprintf("%v/%v/%v/%v/%v", e.hostPrefix, "micro", "images", tenantID, req.ImageID) + } else { + dst := []byte{} + base64.StdEncoding.Encode(dst, buf.Bytes()) + rsp.Base64 = string(dst) + return nil + } + return nil +} diff --git a/image/main.go b/image/main.go new file mode 100644 index 0000000..871b228 --- /dev/null +++ b/image/main.go @@ -0,0 +1,25 @@ +package main + +import ( + "github.com/micro/services/image/handler" + pb "github.com/micro/services/image/proto" + + "github.com/micro/micro/v3/service" + "github.com/micro/micro/v3/service/logger" +) + +func main() { + // Create service + srv := service.New( + service.Name("image"), + service.Version("latest"), + ) + + // Register handler + pb.RegisterImageHandler(srv.Server(), new(handler.Image)) + + // Run service + if err := srv.Run(); err != nil { + logger.Fatal(err) + } +} diff --git a/image/micro.mu b/image/micro.mu new file mode 100644 index 0000000..31d608c --- /dev/null +++ b/image/micro.mu @@ -0,0 +1 @@ +service image diff --git a/image/proto/image.pb.go b/image/proto/image.pb.go new file mode 100644 index 0000000..56d3d45 --- /dev/null +++ b/image/proto/image.pb.go @@ -0,0 +1,607 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.26.0 +// protoc v3.6.1 +// source: proto/image.proto + +package image + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// Upload an image by either sending a base64 encoded image to this endpoint or a URL. +// To resize an image before uploading, see the Resize endpoint. +type UploadRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Base64 encoded image to upload, + // ie. "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" + Base64 string `protobuf:"bytes,1,opt,name=base64,proto3" json:"base64,omitempty"` + // URL of the image to upload + Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"` + // Output name of the image including extension, ie. "cat.png" + ImageID string `protobuf:"bytes,3,opt,name=imageID,proto3" json:"imageID,omitempty"` +} + +func (x *UploadRequest) Reset() { + *x = UploadRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_image_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UploadRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UploadRequest) ProtoMessage() {} + +func (x *UploadRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_image_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UploadRequest.ProtoReflect.Descriptor instead. +func (*UploadRequest) Descriptor() ([]byte, []int) { + return file_proto_image_proto_rawDescGZIP(), []int{0} +} + +func (x *UploadRequest) GetBase64() string { + if x != nil { + return x.Base64 + } + return "" +} + +func (x *UploadRequest) GetUrl() string { + if x != nil { + return x.Url + } + return "" +} + +func (x *UploadRequest) GetImageID() string { + if x != nil { + return x.ImageID + } + return "" +} + +type UploadResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"` +} + +func (x *UploadResponse) Reset() { + *x = UploadResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_image_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UploadResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UploadResponse) ProtoMessage() {} + +func (x *UploadResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_image_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UploadResponse.ProtoReflect.Descriptor instead. +func (*UploadResponse) Descriptor() ([]byte, []int) { + return file_proto_image_proto_rawDescGZIP(), []int{1} +} + +func (x *UploadResponse) GetUrl() string { + if x != nil { + return x.Url + } + return "" +} + +// Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters. +type ResizeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // base64 encoded image to resize, + // ie. "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" + Base64 string `protobuf:"bytes,1,opt,name=base64,proto3" json:"base64,omitempty"` + // url of the image to resize + Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"` + // output name of the image including extension, ie. "cat.png" + ImageID string `protobuf:"bytes,3,opt,name=imageID,proto3" json:"imageID,omitempty"` + // make output a URL and not a base64 response + OutputURL bool `protobuf:"varint,4,opt,name=outputURL,proto3" json:"outputURL,omitempty"` + Width int64 `protobuf:"varint,5,opt,name=width,proto3" json:"width,omitempty"` + Height int64 `protobuf:"varint,6,opt,name=height,proto3" json:"height,omitempty"` +} + +func (x *ResizeRequest) Reset() { + *x = ResizeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_image_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ResizeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ResizeRequest) ProtoMessage() {} + +func (x *ResizeRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_image_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ResizeRequest.ProtoReflect.Descriptor instead. +func (*ResizeRequest) Descriptor() ([]byte, []int) { + return file_proto_image_proto_rawDescGZIP(), []int{2} +} + +func (x *ResizeRequest) GetBase64() string { + if x != nil { + return x.Base64 + } + return "" +} + +func (x *ResizeRequest) GetUrl() string { + if x != nil { + return x.Url + } + return "" +} + +func (x *ResizeRequest) GetImageID() string { + if x != nil { + return x.ImageID + } + return "" +} + +func (x *ResizeRequest) GetOutputURL() bool { + if x != nil { + return x.OutputURL + } + return false +} + +func (x *ResizeRequest) GetWidth() int64 { + if x != nil { + return x.Width + } + return 0 +} + +func (x *ResizeRequest) GetHeight() int64 { + if x != nil { + return x.Height + } + return 0 +} + +type ResizeResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Base64 string `protobuf:"bytes,1,opt,name=base64,proto3" json:"base64,omitempty"` + Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"` +} + +func (x *ResizeResponse) Reset() { + *x = ResizeResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_image_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ResizeResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ResizeResponse) ProtoMessage() {} + +func (x *ResizeResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_image_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ResizeResponse.ProtoReflect.Descriptor instead. +func (*ResizeResponse) Descriptor() ([]byte, []int) { + return file_proto_image_proto_rawDescGZIP(), []int{3} +} + +func (x *ResizeResponse) GetBase64() string { + if x != nil { + return x.Base64 + } + return "" +} + +func (x *ResizeResponse) GetUrl() string { + if x != nil { + return x.Url + } + return "" +} + +// Convert an image from one format (jpeg, png etc.) to an other either on the fly (from base64 to base64), +// or by uploading the conversion result. +type ConvertRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // base64 encoded image to resize, + // ie. "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" + Base64 string `protobuf:"bytes,1,opt,name=base64,proto3" json:"base64,omitempty"` + // url of the image to resize + Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"` + // output name of the image including extension, ie. "cat.png" + ImageID string `protobuf:"bytes,3,opt,name=imageID,proto3" json:"imageID,omitempty"` + // make output a URL and not a base64 response + OutputURL bool `protobuf:"varint,4,opt,name=outputURL,proto3" json:"outputURL,omitempty"` +} + +func (x *ConvertRequest) Reset() { + *x = ConvertRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_image_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ConvertRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ConvertRequest) ProtoMessage() {} + +func (x *ConvertRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_image_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ConvertRequest.ProtoReflect.Descriptor instead. +func (*ConvertRequest) Descriptor() ([]byte, []int) { + return file_proto_image_proto_rawDescGZIP(), []int{4} +} + +func (x *ConvertRequest) GetBase64() string { + if x != nil { + return x.Base64 + } + return "" +} + +func (x *ConvertRequest) GetUrl() string { + if x != nil { + return x.Url + } + return "" +} + +func (x *ConvertRequest) GetImageID() string { + if x != nil { + return x.ImageID + } + return "" +} + +func (x *ConvertRequest) GetOutputURL() bool { + if x != nil { + return x.OutputURL + } + return false +} + +type ConvertResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Base64 string `protobuf:"bytes,1,opt,name=base64,proto3" json:"base64,omitempty"` + Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"` +} + +func (x *ConvertResponse) Reset() { + *x = ConvertResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_image_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ConvertResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ConvertResponse) ProtoMessage() {} + +func (x *ConvertResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_image_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ConvertResponse.ProtoReflect.Descriptor instead. +func (*ConvertResponse) Descriptor() ([]byte, []int) { + return file_proto_image_proto_rawDescGZIP(), []int{5} +} + +func (x *ConvertResponse) GetBase64() string { + if x != nil { + return x.Base64 + } + return "" +} + +func (x *ConvertResponse) GetUrl() string { + if x != nil { + return x.Url + } + return "" +} + +var File_proto_image_proto protoreflect.FileDescriptor + +var file_proto_image_proto_rawDesc = []byte{ + 0x0a, 0x11, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x22, 0x53, 0x0a, 0x0d, 0x55, 0x70, + 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62, + 0x61, 0x73, 0x65, 0x36, 0x34, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x62, 0x61, 0x73, + 0x65, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x03, 0x75, 0x72, 0x6c, 0x12, 0x18, 0x0a, 0x07, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x49, 0x44, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x49, 0x44, 0x22, + 0x22, 0x0a, 0x0e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x75, 0x72, 0x6c, 0x22, 0x9f, 0x01, 0x0a, 0x0d, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x12, 0x10, 0x0a, + 0x03, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x12, + 0x18, 0x0a, 0x07, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x49, 0x44, 0x12, 0x1c, 0x0a, 0x09, 0x6f, 0x75, 0x74, + 0x70, 0x75, 0x74, 0x55, 0x52, 0x4c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x55, 0x52, 0x4c, 0x12, 0x14, 0x0a, 0x05, 0x77, 0x69, 0x64, 0x74, 0x68, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x77, 0x69, 0x64, 0x74, 0x68, 0x12, 0x16, 0x0a, + 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x68, + 0x65, 0x69, 0x67, 0x68, 0x74, 0x22, 0x3a, 0x0a, 0x0e, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, + 0x34, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x12, + 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, + 0x6c, 0x22, 0x72, 0x0a, 0x0e, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x75, + 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x12, 0x18, 0x0a, + 0x07, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x69, 0x6d, 0x61, 0x67, 0x65, 0x49, 0x44, 0x12, 0x1c, 0x0a, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x55, 0x52, 0x4c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x55, 0x52, 0x4c, 0x22, 0x3b, 0x0a, 0x0f, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, + 0x36, 0x34, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, + 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, + 0x72, 0x6c, 0x32, 0xb5, 0x01, 0x0a, 0x05, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x12, 0x37, 0x0a, 0x06, + 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x14, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x55, + 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x69, + 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x06, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x12, + 0x14, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65, + 0x73, 0x69, 0x7a, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3a, + 0x0a, 0x07, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x12, 0x15, 0x2e, 0x69, 0x6d, 0x61, 0x67, + 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x16, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x2e, 0x5a, 0x2c, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2f, 0x73, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x2f, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, +} + +var ( + file_proto_image_proto_rawDescOnce sync.Once + file_proto_image_proto_rawDescData = file_proto_image_proto_rawDesc +) + +func file_proto_image_proto_rawDescGZIP() []byte { + file_proto_image_proto_rawDescOnce.Do(func() { + file_proto_image_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_image_proto_rawDescData) + }) + return file_proto_image_proto_rawDescData +} + +var file_proto_image_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_proto_image_proto_goTypes = []interface{}{ + (*UploadRequest)(nil), // 0: image.UploadRequest + (*UploadResponse)(nil), // 1: image.UploadResponse + (*ResizeRequest)(nil), // 2: image.ResizeRequest + (*ResizeResponse)(nil), // 3: image.ResizeResponse + (*ConvertRequest)(nil), // 4: image.ConvertRequest + (*ConvertResponse)(nil), // 5: image.ConvertResponse +} +var file_proto_image_proto_depIdxs = []int32{ + 0, // 0: image.Image.Upload:input_type -> image.UploadRequest + 2, // 1: image.Image.Resize:input_type -> image.ResizeRequest + 4, // 2: image.Image.Convert:input_type -> image.ConvertRequest + 1, // 3: image.Image.Upload:output_type -> image.UploadResponse + 3, // 4: image.Image.Resize:output_type -> image.ResizeResponse + 5, // 5: image.Image.Convert:output_type -> image.ConvertResponse + 3, // [3:6] is the sub-list for method output_type + 0, // [0:3] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_proto_image_proto_init() } +func file_proto_image_proto_init() { + if File_proto_image_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_proto_image_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UploadRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_image_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UploadResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_image_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ResizeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_image_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ResizeResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_image_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ConvertRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_image_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ConvertResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_proto_image_proto_rawDesc, + NumEnums: 0, + NumMessages: 6, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_proto_image_proto_goTypes, + DependencyIndexes: file_proto_image_proto_depIdxs, + MessageInfos: file_proto_image_proto_msgTypes, + }.Build() + File_proto_image_proto = out.File + file_proto_image_proto_rawDesc = nil + file_proto_image_proto_goTypes = nil + file_proto_image_proto_depIdxs = nil +} diff --git a/image/proto/image.pb.micro.go b/image/proto/image.pb.micro.go new file mode 100644 index 0000000..cc3d43b --- /dev/null +++ b/image/proto/image.pb.micro.go @@ -0,0 +1,127 @@ +// Code generated by protoc-gen-micro. DO NOT EDIT. +// source: proto/image.proto + +package image + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +import ( + context "context" + api "github.com/micro/micro/v3/service/api" + client "github.com/micro/micro/v3/service/client" + server "github.com/micro/micro/v3/service/server" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +// Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint +var _ context.Context +var _ client.Option +var _ server.Option + +// Api Endpoints for Image service + +func NewImageEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + +// Client API for Image service + +type ImageService interface { + Upload(ctx context.Context, in *UploadRequest, opts ...client.CallOption) (*UploadResponse, error) + Resize(ctx context.Context, in *ResizeRequest, opts ...client.CallOption) (*ResizeResponse, error) + Convert(ctx context.Context, in *ConvertRequest, opts ...client.CallOption) (*ConvertResponse, error) +} + +type imageService struct { + c client.Client + name string +} + +func NewImageService(name string, c client.Client) ImageService { + return &imageService{ + c: c, + name: name, + } +} + +func (c *imageService) Upload(ctx context.Context, in *UploadRequest, opts ...client.CallOption) (*UploadResponse, error) { + req := c.c.NewRequest(c.name, "Image.Upload", in) + out := new(UploadResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *imageService) Resize(ctx context.Context, in *ResizeRequest, opts ...client.CallOption) (*ResizeResponse, error) { + req := c.c.NewRequest(c.name, "Image.Resize", in) + out := new(ResizeResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *imageService) Convert(ctx context.Context, in *ConvertRequest, opts ...client.CallOption) (*ConvertResponse, error) { + req := c.c.NewRequest(c.name, "Image.Convert", in) + out := new(ConvertResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Image service + +type ImageHandler interface { + Upload(context.Context, *UploadRequest, *UploadResponse) error + Resize(context.Context, *ResizeRequest, *ResizeResponse) error + Convert(context.Context, *ConvertRequest, *ConvertResponse) error +} + +func RegisterImageHandler(s server.Server, hdlr ImageHandler, opts ...server.HandlerOption) error { + type image interface { + Upload(ctx context.Context, in *UploadRequest, out *UploadResponse) error + Resize(ctx context.Context, in *ResizeRequest, out *ResizeResponse) error + Convert(ctx context.Context, in *ConvertRequest, out *ConvertResponse) error + } + type Image struct { + image + } + h := &imageHandler{hdlr} + return s.Handle(s.NewHandler(&Image{h}, opts...)) +} + +type imageHandler struct { + ImageHandler +} + +func (h *imageHandler) Upload(ctx context.Context, in *UploadRequest, out *UploadResponse) error { + return h.ImageHandler.Upload(ctx, in, out) +} + +func (h *imageHandler) Resize(ctx context.Context, in *ResizeRequest, out *ResizeResponse) error { + return h.ImageHandler.Resize(ctx, in, out) +} + +func (h *imageHandler) Convert(ctx context.Context, in *ConvertRequest, out *ConvertResponse) error { + return h.ImageHandler.Convert(ctx, in, out) +} diff --git a/image/proto/image.proto b/image/proto/image.proto new file mode 100644 index 0000000..1130218 --- /dev/null +++ b/image/proto/image.proto @@ -0,0 +1,67 @@ +syntax = "proto3"; + +package image; + +option go_package = "github.com/micro/services/images/proto;image"; + +service Image { + rpc Upload(UploadRequest) returns (UploadResponse) {} + rpc Resize(ResizeRequest) returns (ResizeResponse) {} + rpc Convert(ConvertRequest) returns (ConvertResponse) {} +} + +// Upload an image by either sending a base64 encoded image to this endpoint or a URL. +// To resize an image before uploading, see the Resize endpoint. +message UploadRequest { + // Base64 encoded image to upload, + // ie. "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" + string base64 = 1; + // URL of the image to upload + string url = 2; + // Output name of the image including extension, ie. "cat.png" + string imageID = 3; +} + +message UploadResponse { + string url = 1; +} + + +// Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters. +message ResizeRequest { + // base64 encoded image to resize, + // ie. "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" + string base64 = 1; + // url of the image to resize + string url = 2; + // output name of the image including extension, ie. "cat.png" + string imageID = 3; + // make output a URL and not a base64 response + bool outputURL = 4; + int64 width = 5; + int64 height = 6; +} + +message ResizeResponse { + string base64 = 1; + string url = 2; +} + +// Convert an image from one format (jpeg, png etc.) to an other either on the fly (from base64 to base64), +// or by uploading the conversion result. +message ConvertRequest { + // base64 encoded image to resize, + // ie. "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" + string base64 = 1; + // url of the image to resize + string url = 2; + // output name of the image including extension, ie. "cat.png" + string imageID = 3; + // make output a URL and not a base64 response + bool outputURL = 4; +} + +message ConvertResponse { + string base64 = 1; + string url = 2; +} \ No newline at end of file