Gitea: Optimize avatar pictures

Created on 13 Nov 2019  路  9Comments  路  Source: go-gitea/gitea

  • Gitea version (or commit ref): pre-1.11 (7b75603ffed7e1bcdde7819e35d86d54d3bfc0ae)

Description

Currently there are few restrictions for the avatars the users can upload. Since the admin has no control on what avatars are uploaded, some effort should be done to reduce their size in bytes on Gitea. I don't mean to limit the file size but to reduce the image size on the server.

Avatars are one of the reasons a page may take a long time for first-load. Currently I've got a 390KB avatar at one test repo, and I'm sure I could upload something heavier.

kinenhancement revieweconfirmed

Most helpful comment

Image size could be reduced to a factor of 2-4 of the maximum displayed avatar size. Afterwards tools like pngcrush or zopflipng (and equivalents for other formats) could be applied to optimize for size.

All 9 comments

Image size could be reduced to a factor of 2-4 of the maximum displayed avatar size. Afterwards tools like pngcrush or zopflipng (and equivalents for other formats) could be applied to optimize for size.

This could be done in the prepare function in the avatar package.

It looks like the prepare function seems to do what we want (mostly). But we could modify it a bit to down size the image before storing it. For additional compression without any external dependencies like pngcrush or zopflipng we could change encoding to a jpeg and decrease the quality using image/jpeg.Encode (but jpg is gross).

Interested in working on this, just need more info on how ya'll would like to proceed.

@tylerchambers That would be cool!

I'm not familiar with jpeg compression techniques, but can it be targeted to a certain file size? (rather than a percentage). A possibility is to define a maximum size (in bytes), and any picture bigger than that can be recompressed in 5~10% steps until getting below the target value. The site admin could configure the size in app.ini. That should maintain a reasonable amount of quality, and users could upload the picture in any supported format. The format will be honored if the file size is within limits.

I think we may store orignal images and thumbnail images.

I think we may store orignal images and thumbnail images.

Oh, true! For the profile page picture. Makes sense.

This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.

@guillep2k Looks good.

@guillep2k doesn't look it can do lossless size optimization, but it's a start for resizing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lunny picture lunny  路  3Comments

jakimfett picture jakimfett  路  3Comments

jonasfranz picture jonasfranz  路  3Comments

BRMateus2 picture BRMateus2  路  3Comments

cookiengineer picture cookiengineer  路  3Comments