mirror of
https://github.com/imgproxy/imgproxy.git
synced 2024-11-29 08:22:11 +02:00
Correct image extending
This commit is contained in:
parent
0bf35d5524
commit
7d92cdd66d
18
process.go
18
process.go
@ -311,18 +311,6 @@ func transformImage(ctx context.Context, img *vipsImage, data []byte, po *proces
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if po.Expand && (po.Width > img.Width() || po.Height > img.Height()) {
|
|
||||||
if err = img.EnsureAlpha(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
hasAlpha = true
|
|
||||||
|
|
||||||
if err = img.Embed(gravityCenter, po.Width, po.Height, 0, 0); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if hasAlpha && (po.Flatten || po.Format == imageTypeJPEG) {
|
if hasAlpha && (po.Flatten || po.Format == imageTypeJPEG) {
|
||||||
if err = img.Flatten(po.Background); err != nil {
|
if err = img.Flatten(po.Background); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -341,6 +329,12 @@ func transformImage(ctx context.Context, img *vipsImage, data []byte, po *proces
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if po.Expand && (po.Width > img.Width() || po.Height > img.Height()) {
|
||||||
|
if err = img.Embed(gravityCenter, po.Width, po.Height, 0, 0, po.Background); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
checkTimeout(ctx)
|
checkTimeout(ctx)
|
||||||
|
|
||||||
if po.Watermark.Enabled {
|
if po.Watermark.Enabled {
|
||||||
|
12
vips.c
12
vips.c
@ -364,8 +364,16 @@ vips_replicate_go(VipsImage *in, VipsImage **out, int width, int height) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
vips_embed_go(VipsImage *in, VipsImage **out, int x, int y, int width, int height) {
|
vips_embed_go(VipsImage *in, VipsImage **out, int x, int y, int width, int height, double *bg, int bgn) {
|
||||||
return vips_embed(in, out, x, y, width, height, NULL);
|
VipsArrayDouble *bga = vips_array_double_new(bg, bgn);
|
||||||
|
int ret = vips_embed(
|
||||||
|
in, out, x, y, width, height,
|
||||||
|
"extend", VIPS_EXTEND_BACKGROUND,
|
||||||
|
"background", bga,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
vips_area_unref((VipsArea *)bga);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
17
vips.go
17
vips.go
@ -575,7 +575,7 @@ func (img *vipsImage) Replicate(width, height int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (img *vipsImage) Embed(gravity gravityType, width, height int, offX, offY int) error {
|
func (img *vipsImage) Embed(gravity gravityType, width, height int, offX, offY int, bg rgbColor) error {
|
||||||
wmWidth := img.Width()
|
wmWidth := img.Width()
|
||||||
wmHeight := img.Height()
|
wmHeight := img.Height()
|
||||||
|
|
||||||
@ -610,8 +610,19 @@ func (img *vipsImage) Embed(gravity gravityType, width, height int, offX, offY i
|
|||||||
top = 0
|
top = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := img.RgbColourspace(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var bgc []C.double
|
||||||
|
if img.HasAlpha() {
|
||||||
|
bgc = []C.double{C.double(0)}
|
||||||
|
} else {
|
||||||
|
bgc = []C.double{C.double(bg.R), C.double(bg.G), C.double(bg.B)}
|
||||||
|
}
|
||||||
|
|
||||||
var tmp *C.VipsImage
|
var tmp *C.VipsImage
|
||||||
if C.vips_embed_go(img.VipsImage, &tmp, C.int(left), C.int(top), C.int(width), C.int(height)) != 0 {
|
if C.vips_embed_go(img.VipsImage, &tmp, C.int(left), C.int(top), C.int(width), C.int(height), &bgc[0], C.int(len(bgc))) != 0 {
|
||||||
return vipsError()
|
return vipsError()
|
||||||
}
|
}
|
||||||
C.swap_and_clear(&img.VipsImage, tmp)
|
C.swap_and_clear(&img.VipsImage, tmp)
|
||||||
@ -655,7 +666,7 @@ func (img *vipsImage) ApplyWatermark(opts *watermarkOptions) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = wm.Embed(opts.Gravity, imgW, imgH, opts.OffsetX, opts.OffsetY); err != nil {
|
if err = wm.Embed(opts.Gravity, imgW, imgH, opts.OffsetX, opts.OffsetY, rgbColor{0, 0, 0}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
vips.h
2
vips.h
@ -68,7 +68,7 @@ int vips_sharpen_go(VipsImage *in, VipsImage **out, double sigma);
|
|||||||
int vips_flatten_go(VipsImage *in, VipsImage **out, double r, double g, double b);
|
int vips_flatten_go(VipsImage *in, VipsImage **out, double r, double g, double b);
|
||||||
|
|
||||||
int vips_replicate_go(VipsImage *in, VipsImage **out, int across, int down);
|
int vips_replicate_go(VipsImage *in, VipsImage **out, int across, int down);
|
||||||
int vips_embed_go(VipsImage *in, VipsImage **out, int x, int y, int width, int height);
|
int vips_embed_go(VipsImage *in, VipsImage **out, int x, int y, int width, int height, double *bg, int bgn);
|
||||||
|
|
||||||
int vips_ensure_alpha(VipsImage *in, VipsImage **out);
|
int vips_ensure_alpha(VipsImage *in, VipsImage **out);
|
||||||
int vips_apply_opacity(VipsImage *in, VipsImage **out, double opacity);
|
int vips_apply_opacity(VipsImage *in, VipsImage **out, double opacity);
|
||||||
|
Loading…
Reference in New Issue
Block a user