mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-04-07 06:50:09 +02:00
Progressive JPEG & interlaced PNG support
This commit is contained in:
parent
a5a46d6fc6
commit
c3d39b2b42
@ -163,6 +163,8 @@ You can also specify a secret to enable authorization with the HTTP `Authorizati
|
||||
|
||||
* `IMGPROXY_QUALITY` — quality of the resulting image, percentage. Default: `80`;
|
||||
* `IMGPROXY_GZIP_COMPRESSION` — GZip compression level. Default: `5`;
|
||||
* `IMGPROXY_JPEG_PROGRESSIVE` — when true, enables progressive compression of JPEG. Default: false;
|
||||
* `IMGPROXY_PNG_INTERLACED` — when true, enables interlaced compression of PNG. Default: false;
|
||||
|
||||
#### Miscellaneous
|
||||
|
||||
|
@ -87,6 +87,8 @@ type config struct {
|
||||
MaxSrcDimension int
|
||||
MaxSrcResolution int
|
||||
|
||||
JpegProgressive bool
|
||||
PngInterlaced bool
|
||||
Quality int
|
||||
GZipCompression int
|
||||
|
||||
@ -140,6 +142,8 @@ func init() {
|
||||
intEnvConfig(&conf.MaxSrcDimension, "IMGPROXY_MAX_SRC_DIMENSION")
|
||||
megaIntEnvConfig(&conf.MaxSrcResolution, "IMGPROXY_MAX_SRC_RESOLUTION")
|
||||
|
||||
boolEnvConfig(&conf.JpegProgressive, "IMGPROXY_JPEG_PROGRESSIVE")
|
||||
boolEnvConfig(&conf.PngInterlaced, "IMGPROXY_PNG_INTERLACED")
|
||||
intEnvConfig(&conf.Quality, "IMGPROXY_QUALITY")
|
||||
intEnvConfig(&conf.GZipCompression, "IMGPROXY_GZIP_COMPRESSION")
|
||||
|
||||
|
24
process.go
24
process.go
@ -81,6 +81,14 @@ var vipsSupportSmartcrop bool
|
||||
var vipsTypeSupportLoad = make(map[imageType]bool)
|
||||
var vipsTypeSupportSave = make(map[imageType]bool)
|
||||
|
||||
type cConfig struct {
|
||||
Quality C.int
|
||||
JpegProgressive C.int
|
||||
PngInterlaced C.int
|
||||
}
|
||||
|
||||
var cConf cConfig
|
||||
|
||||
func initVips() {
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
@ -125,6 +133,16 @@ func initVips() {
|
||||
if int(C.vips_type_find_save_go(C.WEBP)) != 0 {
|
||||
vipsTypeSupportSave[WEBP] = true
|
||||
}
|
||||
|
||||
cConf.Quality = C.int(conf.Quality)
|
||||
|
||||
if conf.JpegProgressive {
|
||||
cConf.JpegProgressive = C.int(1)
|
||||
}
|
||||
|
||||
if conf.PngInterlaced {
|
||||
cConf.PngInterlaced = C.int(1)
|
||||
}
|
||||
}
|
||||
|
||||
func shutdownVips() {
|
||||
@ -366,11 +384,11 @@ func vipsSaveImage(img *C.struct__VipsImage, imgtype imageType) ([]byte, error)
|
||||
|
||||
switch imgtype {
|
||||
case JPEG:
|
||||
err = C.vips_jpegsave_go(img, &ptr, &imgsize, 1, C.int(conf.Quality), 0)
|
||||
err = C.vips_jpegsave_go(img, &ptr, &imgsize, 1, cConf.Quality, cConf.JpegProgressive)
|
||||
case PNG:
|
||||
err = C.vips_pngsave_go(img, &ptr, &imgsize)
|
||||
err = C.vips_pngsave_go(img, &ptr, &imgsize, cConf.PngInterlaced)
|
||||
case WEBP:
|
||||
err = C.vips_webpsave_go(img, &ptr, &imgsize, 1, C.int(conf.Quality))
|
||||
err = C.vips_webpsave_go(img, &ptr, &imgsize, 1, cConf.Quality)
|
||||
}
|
||||
if err != 0 {
|
||||
return nil, vipsError()
|
||||
|
4
vips.h
4
vips.h
@ -198,8 +198,8 @@ vips_jpegsave_go(VipsImage *in, void **buf, size_t *len, int strip, int quality,
|
||||
}
|
||||
|
||||
int
|
||||
vips_pngsave_go(VipsImage *in, void **buf, size_t *len) {
|
||||
return vips_pngsave_buffer(in, buf, len, "filter", VIPS_FOREIGN_PNG_FILTER_NONE, NULL);
|
||||
vips_pngsave_go(VipsImage *in, void **buf, size_t *len, int interlace) {
|
||||
return vips_pngsave_buffer(in, buf, len, "filter", VIPS_FOREIGN_PNG_FILTER_NONE, "interlace", interlace, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
|
Loading…
x
Reference in New Issue
Block a user