fix (image): thumbnail generation for small images: libvips edge case - #93

This commit is contained in:
Mickael Kerjean 2018-08-28 19:21:30 +10:00
parent bfacd4bcc5
commit f561608a3c
3 changed files with 25 additions and 6 deletions

View file

@ -21,6 +21,7 @@
display: flex;
flex-grow: 1;
height: 100%;
width: 100%;
text-align: center;
background: #525659;
overflow: hidden;

View file

@ -20,12 +20,23 @@ int resizer_process(const char *filename, void **buf, size_t *len, int size, int
quality = quality > 100 || quality < 0 ? 80 : quality;
exif = exif == 0 ? TRUE : FALSE;
err = vips_thumbnail(filename, &img, size,
"size", VIPS_SIZE_DOWN,
"auto_rotate", TRUE,
"crop", crop,
NULL
);
if(crop == VIPS_INTERESTING_CENTRE){
// Generate a thumbnails: a square picture crop in the center
err = vips_thumbnail(filename, &img, size,
"size", VIPS_SIZE_BOTH,
"auto_rotate", TRUE,
"crop", VIPS_INTERESTING_CENTRE,
NULL
);
}else{
// normal resize of an image with libvips
err = vips_thumbnail(filename, &img, size,
"size", VIPS_SIZE_DOWN,
"auto_rotate", TRUE,
"crop", VIPS_INTERESTING_NONE,
NULL
);
}
if(err != 0){
return err;
}

View file

@ -27,6 +27,13 @@ func ProcessFileBeforeSend(reader io.Reader, ctx *App, req *http.Request, res *h
(*res).Header().Set("Content-Type", mType)
if strings.HasPrefix(mType, "image/") {
if mType == "image/svg" {
(*res).Header().Set("Content-Type", "image/svg+xml")
return reader, nil
} else if mType == "image/x-icon" {
return reader, nil
}
if query.Get("thumbnail") != "true" && query.Get("size") == "" {
return reader, nil
}