Skip to content

Commit

Permalink
generate .jpeg thumbnails for .png images
Browse files Browse the repository at this point in the history
  • Loading branch information
ShoshinNikita committed Jul 18, 2023
1 parent 8b93a4f commit f0321f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/thumbnails_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestThumbnailGeneration(t *testing.T) {
mimeType string
}{
{imageType: "jpg", file: "Images/birds-g64b44607c_640.jpg", mimeType: "image/jpeg"},
{imageType: "png", file: "Images/ytrewq.png", mimeType: "image/png"},
{imageType: "png", file: "Images/ytrewq.png", mimeType: "image/jpeg"},
{imageType: "webp", file: "Images/qwerty.webp", mimeType: "image/webp"},
{imageType: "heic", file: "Images/asdfgh.heic", mimeType: "image/jpeg"}, // we should generate .jpeg thumbnails for .heic images
} {
Expand Down
10 changes: 4 additions & 6 deletions thumbnails/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,11 @@ func createCacheFileFromTempFile(tempFile *os.File, cacheFilepath string, origin
func resizeWithVips(originalFile, cacheFile string, fileID rview.FileID) error {
output := cacheFile
switch getImageType(fileID) {
case heicImageType:
// We generate .jpeg thumbnails for .heic images.
case pngImageType, heicImageType:
// We generate .jpeg thumbnails for .png and .heic images.
fallthrough
case jpegImageType:
output += "[Q=80,optimize_coding,strip]"
case pngImageType:
output += "[strip]"
case webpImageType:
output += "[strip]"
default:
Expand Down Expand Up @@ -459,8 +457,8 @@ func (c *cacheWrapper) Remove(id rview.FileID) error {
// convertToThumbnailFileID returns a file id for working with the thumbnail cache.
func convertToThumbnailFileID(id rview.FileID) rview.FileID {
switch id.GetExt() {
case ".heic":
// We generate .jpeg thumbnails for .heic images.
case ".png", ".heic":
// We generate .jpeg thumbnails for .png and .heic images.
path := id.GetPath() + ".jpeg"
return rview.NewFileID(path, id.GetModTime().Unix())

Expand Down

0 comments on commit f0321f0

Please sign in to comment.