mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-03-17 20:17:48 +02:00
Optimize memory usage in some scenarios
This commit is contained in:
parent
48eb5f938a
commit
ca9fb6c586
@ -3,6 +3,7 @@
|
||||
## [Unreleased]
|
||||
### Change
|
||||
- Add support for Managed Identity or Service Principal credentials to Azure Blob Storage integration.
|
||||
- Optimize memory usage in some scenarios.
|
||||
|
||||
### Fix
|
||||
- Fix craches in some cases when using OpenTelemetry in Amazon ECS.
|
||||
|
@ -35,7 +35,7 @@ var mainPipeline = pipeline{
|
||||
flatten,
|
||||
watermark,
|
||||
exportColorProfile,
|
||||
finalize,
|
||||
stripMetadata,
|
||||
}
|
||||
|
||||
func isImageTypePreferred(imgtype imagetype.Type) bool {
|
||||
@ -182,10 +182,6 @@ func transformAnimated(ctx context.Context, img *vips.Image, po *options.Process
|
||||
return err
|
||||
}
|
||||
|
||||
if err = img.CopyMemory(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(delay) == 0 {
|
||||
delay = make([]int, framesCount)
|
||||
for i := range delay {
|
||||
|
@ -7,6 +7,14 @@ import (
|
||||
)
|
||||
|
||||
func rotateAndFlip(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error {
|
||||
if pctx.angle%360 == 0 && po.Rotate%360 == 0 && !pctx.flip {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := img.CopyMemory(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := img.Rotate(pctx.angle); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -7,15 +7,17 @@ import (
|
||||
)
|
||||
|
||||
func scale(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error {
|
||||
if pctx.wscale != 1 || pctx.hscale != 1 {
|
||||
wscale, hscale := pctx.wscale, pctx.hscale
|
||||
if (pctx.angle+po.Rotate)%180 == 90 {
|
||||
wscale, hscale = hscale, wscale
|
||||
}
|
||||
if pctx.wscale == 1 && pctx.hscale == 1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := img.Resize(wscale, hscale); err != nil {
|
||||
return err
|
||||
}
|
||||
wscale, hscale := pctx.wscale, pctx.hscale
|
||||
if (pctx.angle+po.Rotate)%180 == 90 {
|
||||
wscale, hscale = hscale, wscale
|
||||
}
|
||||
|
||||
if err := img.Resize(wscale, hscale); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return img.CopyMemory()
|
||||
|
@ -92,29 +92,31 @@ func stripXMP(img *vips.Image) []byte {
|
||||
return xmpData
|
||||
}
|
||||
|
||||
func finalize(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error {
|
||||
if po.StripMetadata {
|
||||
var iptcData, xmpData []byte
|
||||
func stripMetadata(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error {
|
||||
if !po.StripMetadata {
|
||||
return nil
|
||||
}
|
||||
|
||||
if po.KeepCopyright {
|
||||
iptcData = stripIPTC(img)
|
||||
xmpData = stripXMP(img)
|
||||
var iptcData, xmpData []byte
|
||||
|
||||
if po.KeepCopyright {
|
||||
iptcData = stripIPTC(img)
|
||||
xmpData = stripXMP(img)
|
||||
}
|
||||
|
||||
if err := img.Strip(po.KeepCopyright); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if po.KeepCopyright {
|
||||
if len(iptcData) > 0 {
|
||||
img.SetBlob("iptc-data", iptcData)
|
||||
}
|
||||
|
||||
if err := img.Strip(po.KeepCopyright); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if po.KeepCopyright {
|
||||
if len(iptcData) > 0 {
|
||||
img.SetBlob("iptc-data", iptcData)
|
||||
}
|
||||
|
||||
if len(xmpData) > 0 {
|
||||
img.SetBlob("xmp-data", xmpData)
|
||||
}
|
||||
if len(xmpData) > 0 {
|
||||
img.SetBlob("xmp-data", xmpData)
|
||||
}
|
||||
}
|
||||
|
||||
return img.CopyMemory()
|
||||
return nil
|
||||
}
|
@ -17,7 +17,6 @@ var watermarkPipeline = pipeline{
|
||||
scale,
|
||||
rotateAndFlip,
|
||||
padding,
|
||||
finalize,
|
||||
}
|
||||
|
||||
func prepareWatermark(wm *vips.Image, wmData *imagedata.ImageData, opts *options.WatermarkOptions, imgWidth, imgHeight int) error {
|
||||
@ -62,10 +61,6 @@ func applyWatermark(img *vips.Image, wmData *imagedata.ImageData, opts *options.
|
||||
return err
|
||||
}
|
||||
|
||||
if err := img.CopyMemory(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
wm := new(vips.Image)
|
||||
defer wm.Clear()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user