mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-10 20:22:31 +02:00
Progressive JPEG & interlaced PNG support
This commit is contained in:
@@ -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_QUALITY` — quality of the resulting image, percentage. Default: `80`;
|
||||||
* `IMGPROXY_GZIP_COMPRESSION` — GZip compression level. Default: `5`;
|
* `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
|
#### Miscellaneous
|
||||||
|
|
||||||
|
@@ -87,6 +87,8 @@ type config struct {
|
|||||||
MaxSrcDimension int
|
MaxSrcDimension int
|
||||||
MaxSrcResolution int
|
MaxSrcResolution int
|
||||||
|
|
||||||
|
JpegProgressive bool
|
||||||
|
PngInterlaced bool
|
||||||
Quality int
|
Quality int
|
||||||
GZipCompression int
|
GZipCompression int
|
||||||
|
|
||||||
@@ -140,6 +142,8 @@ func init() {
|
|||||||
intEnvConfig(&conf.MaxSrcDimension, "IMGPROXY_MAX_SRC_DIMENSION")
|
intEnvConfig(&conf.MaxSrcDimension, "IMGPROXY_MAX_SRC_DIMENSION")
|
||||||
megaIntEnvConfig(&conf.MaxSrcResolution, "IMGPROXY_MAX_SRC_RESOLUTION")
|
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.Quality, "IMGPROXY_QUALITY")
|
||||||
intEnvConfig(&conf.GZipCompression, "IMGPROXY_GZIP_COMPRESSION")
|
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 vipsTypeSupportLoad = make(map[imageType]bool)
|
||||||
var vipsTypeSupportSave = 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() {
|
func initVips() {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
@@ -125,6 +133,16 @@ func initVips() {
|
|||||||
if int(C.vips_type_find_save_go(C.WEBP)) != 0 {
|
if int(C.vips_type_find_save_go(C.WEBP)) != 0 {
|
||||||
vipsTypeSupportSave[WEBP] = true
|
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() {
|
func shutdownVips() {
|
||||||
@@ -366,11 +384,11 @@ func vipsSaveImage(img *C.struct__VipsImage, imgtype imageType) ([]byte, error)
|
|||||||
|
|
||||||
switch imgtype {
|
switch imgtype {
|
||||||
case JPEG:
|
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:
|
case PNG:
|
||||||
err = C.vips_pngsave_go(img, &ptr, &imgsize)
|
err = C.vips_pngsave_go(img, &ptr, &imgsize, cConf.PngInterlaced)
|
||||||
case WEBP:
|
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 {
|
if err != 0 {
|
||||||
return nil, vipsError()
|
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
|
int
|
||||||
vips_pngsave_go(VipsImage *in, void **buf, size_t *len) {
|
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, NULL);
|
return vips_pngsave_buffer(in, buf, len, "filter", VIPS_FOREIGN_PNG_FILTER_NONE, "interlace", interlace, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Reference in New Issue
Block a user