@@ -80,7 +80,7 @@ func getValidFileNameWithDupIndex(path string, filename string, duplicateIndex i
80
80
81
81
// path doesn't exist so we can return this path
82
82
if _ , err := os .Stat (fullpath ); os .IsNotExist (err ) {
83
- return dupStr + filename
83
+ return strings . ToUpper ( dupStr + filename )
84
84
}
85
85
86
86
//otherwise increase file index and
@@ -297,18 +297,54 @@ func GetImageDimensions(imgData io.Reader, ext string) (width int, height int, e
297
297
if err != nil {
298
298
return - 1 , - 1 , fmt .Errorf ("failed to get the original image dimensions %v" , err )
299
299
}
300
- return imgConfig .Width , imgConfig .Width , nil
300
+ return imgConfig .Width , imgConfig .Height , nil
301
301
}
302
302
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 )
305
305
}
306
306
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 , "/" ) {
309
346
endpoint += "/"
310
347
}
311
- ext := filepath .Ext (filename )
312
348
bOps , err := json .Marshal (ops .Ops )
313
349
if err != nil {
314
350
return nil , fmt .Errorf ("json.Marshal %v" , err )
0 commit comments