loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove nfnt/resize and oliamb/cutter (#25999)

The package `github.com/nfnt/resize` is deprecated and archived by the
author. `github.com/oliamb/cutter` is not maintained since 2018. We
could use `golang.org/x/image/draw` instead.

authored by

harryzcy and committed by
GitHub
ec227d66 0ef2919b

+36 -39
-10
assets/go-licenses.json
··· 805 805 "licenseText": "MIT License\n\nCopyright (c) 2022 The Gitea Authors\nCopyright (c) 2019\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n" 806 806 }, 807 807 { 808 - "name": "github.com/nfnt/resize", 809 - "path": "github.com/nfnt/resize/LICENSE", 810 - "licenseText": "Copyright (c) 2012, Jan Schlicht \u003cjan.schlicht@gmail.com\u003e\n\nPermission to use, copy, modify, and/or distribute this software for any purpose\nwith or without fee is hereby granted, provided that the above copyright notice\nand this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\nFITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS\nOF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER\nTORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\nTHIS SOFTWARE.\n" 811 - }, 812 - { 813 808 "name": "github.com/niklasfasching/go-org/org", 814 809 "path": "github.com/niklasfasching/go-org/org/LICENSE", 815 810 "licenseText": "MIT License\n\nCopyright (c) 2018 Niklas Fasching\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n" ··· 823 818 "name": "github.com/olekukonko/tablewriter", 824 819 "path": "github.com/olekukonko/tablewriter/LICENSE.md", 825 820 "licenseText": "Copyright (C) 2014 by Oleku Konko\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n" 826 - }, 827 - { 828 - "name": "github.com/oliamb/cutter", 829 - "path": "github.com/oliamb/cutter/LICENSE", 830 - "licenseText": "The MIT License (MIT)\n\nCopyright (c) 2014 Olivier Amblet\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n" 831 821 }, 832 822 { 833 823 "name": "github.com/olivere/elastic/v7",
-2
go.mod
··· 81 81 github.com/minio/sha256-simd v1.0.1 82 82 github.com/msteinert/pam v1.1.0 83 83 github.com/nektos/act v0.2.48 84 - github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 85 84 github.com/niklasfasching/go-org v1.7.0 86 - github.com/oliamb/cutter v0.2.2 87 85 github.com/olivere/elastic/v7 v7.0.32 88 86 github.com/opencontainers/go-digest v1.0.0 89 87 github.com/opencontainers/image-spec v1.1.0-rc4
-4
go.sum
··· 921 921 github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= 922 922 github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= 923 923 github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= 924 - github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= 925 - github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= 926 924 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= 927 925 github.com/niklasfasching/go-org v1.7.0 h1:vyMdcMWWTe/XmANk19F4k8XGBYg0GQ/gJGMimOjGMek= 928 926 github.com/niklasfasching/go-org v1.7.0/go.mod h1:WuVm4d45oePiE0eX25GqTDQIt/qPW1T9DGkRscqLW5o= ··· 939 937 github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= 940 938 github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= 941 939 github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= 942 - github.com/oliamb/cutter v0.2.2 h1:Lfwkya0HHNU1YLnGv2hTkzHfasrSMkgv4Dn+5rmlk3k= 943 - github.com/oliamb/cutter v0.2.2/go.mod h1:4BenG2/4GuRBDbVm/OPahDVqbrOemzpPiG5mi1iryBU= 944 940 github.com/olivere/elastic/v7 v7.0.32 h1:R7CXvbu8Eq+WlsLgxmKVKPox0oOwAE/2T9Si5BnvK6E= 945 941 github.com/olivere/elastic/v7 v7.0.32/go.mod h1:c7PVmLe3Fxq77PIfY/bZmxY/TAamBhCzZ8xDOE09a9k= 946 942 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
+36 -23
modules/avatar/avatar.go
··· 17 17 "code.gitea.io/gitea/modules/avatar/identicon" 18 18 "code.gitea.io/gitea/modules/setting" 19 19 20 - "github.com/nfnt/resize" 21 - "github.com/oliamb/cutter" 20 + "golang.org/x/image/draw" 22 21 23 22 _ "golang.org/x/image/webp" // for processing webp images 24 23 ) ··· 81 80 } 82 81 83 82 // try to crop and resize the origin image if necessary 84 - if imgCfg.Width != imgCfg.Height { 85 - var newSize, ax, ay int 86 - if imgCfg.Width > imgCfg.Height { 87 - newSize = imgCfg.Height 88 - ax = (imgCfg.Width - imgCfg.Height) / 2 89 - } else { 90 - newSize = imgCfg.Width 91 - ay = (imgCfg.Height - imgCfg.Width) / 2 92 - } 93 - 94 - img, err = cutter.Crop(img, cutter.Config{ 95 - Width: newSize, 96 - Height: newSize, 97 - Anchor: image.Point{X: ax, Y: ay}, 98 - }) 99 - if err != nil { 100 - return nil, err 101 - } 102 - } 83 + img = cropSquare(img) 103 84 104 - targetSize := uint(DefaultAvatarSize * setting.Avatar.RenderedSizeFactor) 105 - img = resize.Resize(targetSize, targetSize, img, resize.Bilinear) 85 + targetSize := DefaultAvatarSize * setting.Avatar.RenderedSizeFactor 86 + img = scale(img, targetSize, targetSize, draw.BiLinear) 106 87 107 88 // try to encode the cropped/resized image to png 108 89 bs := bytes.Buffer{} ··· 124 105 func ProcessAvatarImage(data []byte) ([]byte, error) { 125 106 return processAvatarImage(data, setting.Avatar.MaxOriginSize) 126 107 } 108 + 109 + // scale resizes the image to width x height using the given scaler. 110 + func scale(src image.Image, width, height int, scale draw.Scaler) image.Image { 111 + rect := image.Rect(0, 0, width, height) 112 + dst := image.NewRGBA(rect) 113 + scale.Scale(dst, rect, src, src.Bounds(), draw.Over, nil) 114 + return dst 115 + } 116 + 117 + // cropSquare crops the largest square image from the center of the image. 118 + // If the image is already square, it is returned unchanged. 119 + func cropSquare(src image.Image) image.Image { 120 + bounds := src.Bounds() 121 + if bounds.Dx() == bounds.Dy() { 122 + return src 123 + } 124 + 125 + var rect image.Rectangle 126 + if bounds.Dx() > bounds.Dy() { 127 + // width > height 128 + size := bounds.Dy() 129 + rect = image.Rect((bounds.Dx()-size)/2, 0, (bounds.Dx()+size)/2, size) 130 + } else { 131 + // width < height 132 + size := bounds.Dx() 133 + rect = image.Rect(0, (bounds.Dy()-size)/2, size, (bounds.Dy()+size)/2) 134 + } 135 + 136 + dst := image.NewRGBA(rect) 137 + draw.Draw(dst, rect, src, rect.Min, draw.Src) 138 + return dst 139 + }