-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add banner support for communities
Add banner image as a special `IdentityImage` beside "thumbnail" and "large" Banner input cropped image processing - Resize to keep in the limits of `BannerDim` - Encode to match the file size limits define for banner - Don't scale up. This can be done efficiently in the UI Changes to `images` module - Refactor `EncodeToBestSize` as `EncodeToLimits` to accept arbitrary dimensions and allow for custom size - Define `DimensionLimits` for banner not to exceed 450 KB and a rough estimate for the ideal size
- Loading branch information
1 parent
7227ae1
commit 44125b2
Showing
10 changed files
with
204 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package images | ||
|
||
type CroppedImage struct { | ||
ImagePath string `json:"imagePath"` | ||
X int `json:"x"` | ||
Y int `json:"y"` | ||
Width int `json:"width"` | ||
Height int `json:"height"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package images | ||
|
||
import ( | ||
"image" | ||
"image/png" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGenerateBannerImage_NoScaleUp(t *testing.T) { | ||
// Test image 256x256 | ||
testImage := path + "status.png" | ||
identityImage, err := GenerateBannerImage(testImage, 50, 50, 150, 100) | ||
|
||
require.NoError(t, err) | ||
require.Exactly(t, identityImage.Name, BannerIdentityName) | ||
require.Positive(t, len(identityImage.Payload)) | ||
// Ensure we don't scale it up. That will be done inefficiently in backend instead of frontend | ||
require.Exactly(t, identityImage.Width, 100) | ||
require.Exactly(t, identityImage.Height, 50) | ||
require.Exactly(t, identityImage.FileSize, len(identityImage.Payload)) | ||
require.Exactly(t, identityImage.ResizeTarget, int(BannerDim)) | ||
} | ||
|
||
func TestGenerateBannerImage_ShrinkOnly(t *testing.T) { | ||
// Generate test image bigger than BannerDim | ||
testImage := image.NewRGBA(image.Rect(0, 0, int(BannerDim)+10, int(BannerDim)+20)) | ||
|
||
tmpTestFilePath := t.TempDir() + "/test.png" | ||
file, err := os.Create(tmpTestFilePath) | ||
require.NoError(t, err) | ||
defer file.Close() | ||
|
||
err = png.Encode(file, testImage) | ||
require.NoError(t, err) | ||
|
||
identityImage, error := GenerateBannerImage(tmpTestFilePath, 0, 0, int(BannerDim)+5, int(BannerDim)+10) | ||
|
||
require.NoError(t, error) | ||
require.Positive(t, len(identityImage.Payload)) | ||
// Ensure we scale it down by the small side | ||
require.Exactly(t, identityImage.Width, int(BannerDim)) | ||
require.Exactly(t, identityImage.Height, 805) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters