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