Skip to content

Commit 42066e0

Browse files
committed
latest code
1 parent b84dfb7 commit 42066e0

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

fileupload.go

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func getValidFileNameWithDupIndex(path string, filename string, duplicateIndex i
8080

8181
// path doesn't exist so we can return this path
8282
if _, err := os.Stat(fullpath); os.IsNotExist(err) {
83-
return dupStr + filename
83+
return strings.ToUpper(dupStr + filename)
8484
}
8585

8686
//otherwise increase file index and
@@ -297,18 +297,54 @@ func GetImageDimensions(imgData io.Reader, ext string) (width int, height int, e
297297
if err != nil {
298298
return -1, -1, fmt.Errorf("failed to get the original image dimensions %v", err)
299299
}
300-
return imgConfig.Width, imgConfig.Width, nil
300+
return imgConfig.Width, imgConfig.Height, nil
301301
}
302302

303-
func ProcessImage(filename string, imgData io.Reader, ops *operations) (byts []byte, err error) {
304-
return ProcessImageWithEndpoint(os.Getenv("IMAGE_PROCESSING_ENDPOINT"), filename, imgData, ops)
303+
func ProcessImage(ext string, imgData io.Reader, ops *operations) (byts []byte, err error) {
304+
return ProcessImageWithEndpoint(os.Getenv("IMAGE_PROCESSING_ENDPOINT"), ext, imgData, ops)
305305
}
306306

307-
func ProcessImageWithEndpoint(endpoint string, filename string, imgData io.Reader, ops *operations) (b []byte, err error) {
308-
if strings.HasSuffix(endpoint, "/") {
307+
type ImageMeta interface {
308+
// GetUniqueID() string
309+
GetFileName(string) string
310+
// GetFinalImageSize() string
311+
GetScale() float64
312+
GetOriginalWidth() float64
313+
GetOriginalHeight() float64
314+
GetX() float64
315+
GetY() float64
316+
GetCropWidth() float64
317+
GetCropHeight() float64
318+
GetExt() string
319+
}
320+
321+
func ProcessedImageScaleAndCropFromMeta(meta ImageMeta, imgData io.Reader) ([]byte, error) {
322+
// first do your main processing
323+
ops := NewProcessingOps()
324+
// if meta.GetScale() > 1 {
325+
ops.Add("enlarge")
326+
// } else {
327+
// ops.Add("resize")
328+
// }
329+
330+
relativeWidth := meta.GetOriginalWidth() * meta.GetScale()
331+
ops.LastOp().AddFloat("width", relativeWidth)
332+
relativeHeight := meta.GetOriginalHeight() * meta.GetScale()
333+
ops.LastOp().AddFloat("height", relativeHeight)
334+
ops.Add("extract")
335+
ops.LastOp().AddFloat("left", meta.GetX())
336+
ops.LastOp().AddFloat("top", meta.GetY())
337+
ops.LastOp().AddFloat("areawidth", meta.GetCropWidth())
338+
ops.LastOp().AddFloat("areaheight", meta.GetCropWidth())
339+
340+
// return ProcessImageWithEndpoint(os.Getenv("IMAGE_PROCESSING_ENDPOINT"), meta.GetExt(), bytes.NewBuffer(meta.GetBytes()), ops) // dont pass bytes gets yuck with concurrency
341+
return ProcessImageWithEndpoint(os.Getenv("IMAGE_PROCESSING_ENDPOINT"), meta.GetExt(), imgData, ops)
342+
}
343+
344+
func ProcessImageWithEndpoint(endpoint string, ext string, imgData io.Reader, ops *operations) (b []byte, err error) {
345+
if !strings.HasSuffix(endpoint, "/") {
309346
endpoint += "/"
310347
}
311-
ext := filepath.Ext(filename)
312348
bOps, err := json.Marshal(ops.Ops)
313349
if err != nil {
314350
return nil, fmt.Errorf("json.Marshal %v", err)

0 commit comments

Comments
 (0)