aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web
diff options
context:
space:
mode:
authorJakobDev <jakobdev@gmx.de>2023-07-31 07:04:45 +0200
committerGitHub <noreply@github.com>2023-07-31 05:04:45 +0000
commitaba9096999798efef448bee2f289917069f9b599 (patch)
treea048674a1340b9b69aaff4d4904135b573e7d4bc /routers/web
parent983167cf49cd64c7a1f28c39aff03e00dd387990 (diff)
downloadgitea-aba9096999798efef448bee2f289917069f9b599.tar.gz
gitea-aba9096999798efef448bee2f289917069f9b599.zip
Show image size on view page (#25884)
This simply shows the Image size on the view page. This is useful, if you search a image with a specific size. ![grafik](https://github.com/go-gitea/gitea/assets/15185051/9868e361-1c2e-447f-b824-70aa28bafcbc)
Diffstat (limited to 'routers/web')
-rw-r--r--routers/web/repo/view.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go
index ae22bae9c1..9e6b3e7825 100644
--- a/routers/web/repo/view.go
+++ b/routers/web/repo/view.go
@@ -9,6 +9,7 @@ import (
gocontext "context"
"encoding/base64"
"fmt"
+ "image"
"io"
"net/http"
"net/url"
@@ -16,6 +17,10 @@ import (
"strings"
"time"
+ _ "image/gif" // for processing gif images
+ _ "image/jpeg" // for processing jpeg images
+ _ "image/png" // for processing png images
+
activities_model "code.gitea.io/gitea/models/activities"
admin_model "code.gitea.io/gitea/models/admin"
asymkey_model "code.gitea.io/gitea/models/asymkey"
@@ -44,6 +49,9 @@ import (
issue_service "code.gitea.io/gitea/services/issue"
"github.com/nektos/act/pkg/model"
+
+ _ "golang.org/x/image/bmp" // for processing bmp images
+ _ "golang.org/x/image/webp" // for processing webp images
)
const (
@@ -578,6 +586,15 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
}
}
+ if fInfo.st.IsImage() && !fInfo.st.IsSvgImage() {
+ img, _, err := image.DecodeConfig(bytes.NewReader(buf))
+ if err == nil {
+ // There are Image formats go can't decode
+ // Instead of throwing an error in that case, we show the size only when we can decode
+ ctx.Data["ImageSize"] = fmt.Sprintf("%dx%dpx", img.Width, img.Height)
+ }
+ }
+
if ctx.Repo.CanEnableEditor(ctx, ctx.Doer) {
if lfsLock != nil && lfsLock.OwnerID != ctx.Doer.ID {
ctx.Data["CanDeleteFile"] = false