mirror of
https://github.com/h2non/imaginary.git
synced 2026-05-29 11:18:41 +02:00
Return with and heigh of the generated images (#382)
* Return with and heigh of the generated images Use case: When using the fit image transformation, it is helpful to know the size of the resulting image without having to either read the image locally or do another request to the info endpoint. Used in: https://github.com/nextcloud/server/pull/24166 Signed-off-by: Carl Schwan <carl@carlschwan.eu> * Make mimetype support always return true * Add command line option to enable this feature Signed-off-by: Carl Schwan <carl@carlschwan.eu> * refactor: remove deprecated X- prefix in response headers Co-authored-by: Tom <tomas@aparicio.me>
This commit is contained in:
@@ -133,6 +133,13 @@ func imageHandler(w http.ResponseWriter, r *http.Request, buf []byte, operation
|
||||
// Expose Content-Length response header
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(image.Body)))
|
||||
w.Header().Set("Content-Type", image.Mime)
|
||||
if image.Mime != "application/json" && o.ReturnSize {
|
||||
meta, err := bimg.Metadata(image.Body)
|
||||
if err == nil {
|
||||
w.Header().Set("Image-Width", strconv.Itoa(meta.Size.Width))
|
||||
w.Header().Set("Image-Height", strconv.Itoa(meta.Size.Height))
|
||||
}
|
||||
}
|
||||
if vary != "" {
|
||||
w.Header().Set("Vary", vary)
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ var (
|
||||
aMRelease = flag.Int("mrelease", 30, "OS memory release interval in seconds")
|
||||
aCpus = flag.Int("cpus", runtime.GOMAXPROCS(-1), "Number of cpu cores to use")
|
||||
aLogLevel = flag.String("log-level", "info", "Define log level for http-server. E.g: info,warning,error")
|
||||
aReturnSize = flag.Bool("return-size", false, "Return the image size in the HTTP headers")
|
||||
)
|
||||
|
||||
const usage = `imaginary %s
|
||||
@@ -106,6 +107,7 @@ Options:
|
||||
(default for current machine is %d cores)
|
||||
-log-level Set log level for http-server. E.g: info,warning,error [default: info].
|
||||
Or can use the environment variable GOLANG_LOG=info.
|
||||
-return-size Return the image size with X-Width and X-Height HTTP header. [default: disabled].
|
||||
`
|
||||
|
||||
type URLSignature struct {
|
||||
@@ -157,6 +159,7 @@ func main() {
|
||||
AllowedOrigins: parseOrigins(*aAllowedOrigins),
|
||||
MaxAllowedSize: *aMaxAllowedSize,
|
||||
LogLevel: getLogLevel(*aLogLevel),
|
||||
ReturnSize: *aReturnSize,
|
||||
}
|
||||
|
||||
// Show warning if gzip flag is passed
|
||||
|
||||
Reference in New Issue
Block a user