Skip to content

Commit

Permalink
fix(images): remove avif
Browse files Browse the repository at this point in the history
Memory constrains and limitations on both libvips and libheif side, it isn't safe to implement this now into a small server.
  • Loading branch information
Gusted committed Jun 30, 2021
1 parent 925687d commit 9e13023
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 29 deletions.
4 changes: 2 additions & 2 deletions docs/endpoints.MD
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ this is normally used as updateURL and installation URL.

### Get style's preview
```
GET /style/preview/<id>.<jpeg | webp | avif>
GET /style/preview/<id>.<jpeg | webp>
```
Gets an optimized jpeg/webp/avif version of the style's preview.
Gets an optimized jpeg/webp version of the style's preview.

### List all styles
```
Expand Down
16 changes: 0 additions & 16 deletions handlers/api/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,6 @@ func GetPreviewScreenshot(c *fiber.Ctx) error {
}
stat = info.WebP
mimeType = "image/webp"
case "avif":
fileName = images.CacheFolder + styleID + ".avif"
if info.Avif == nil {
err = images.DecodeImage(orignalFile, fileName, images.ImageTypeAVIF)
if err != nil {
return notFound(c)
}
avifStat, err := os.Stat(fileName)
if err != nil {
return notFound(c)
}
stat = avifStat
break
}
stat = info.Avif
mimeType = "image/avif"
}

if stat == nil || fileName == "" {
Expand Down
2 changes: 0 additions & 2 deletions handlers/style/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,12 @@ func EditPost(c *fiber.Ctx) error {
// So we don't care about the error.
_ = os.Remove(images.CacheFolder + styleID + ".jpeg")
_ = os.Remove(images.CacheFolder + styleID + ".webp")
_ = os.Remove(images.CacheFolder + styleID + ".avif")

q.Preview = "https://userstyles.world/api/preview/" + styleID + ".jpeg"
}

if q.Preview != s.Preview {
_ = os.Remove(images.CacheFolder + styleID + ".original")
_ = os.Remove(images.CacheFolder + styleID + ".avif")
_ = os.Remove(images.CacheFolder + styleID + ".jpeg")
_ = os.Remove(images.CacheFolder + styleID + ".webp")
}
Expand Down
3 changes: 0 additions & 3 deletions modules/images/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

type ImageInfo struct {
Original fs.FileInfo
Avif fs.FileInfo
Jpeg fs.FileInfo
WebP fs.FileInfo
}
Expand All @@ -39,7 +38,6 @@ func GetImageFromStyle(id string) (ImageInfo, error) {
template := CacheFolder + id
original := template + ".original"
jpeg := template + ".jpeg"
avif := template + ".avif"
webp := template + ".webp"
if fileExist(original) == nil {
style, err := models.GetStyleByID(id)
Expand Down Expand Up @@ -76,7 +74,6 @@ func GetImageFromStyle(id string) (ImageInfo, error) {

return ImageInfo{
Original: fileExist(original),
Avif: fileExist(avif),
WebP: fileExist(webp),
Jpeg: fileExist(jpeg),
}, nil
Expand Down
5 changes: 1 addition & 4 deletions modules/images/processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (
type ImageType int

const (
ImageTypeAVIF ImageType = iota
ImageTypeWEBP
ImageTypeWEBP ImageType = iota
ImageTypeJPEG
)

Expand Down Expand Up @@ -50,8 +49,6 @@ func DecodeImage(original, newPath string, imageType ImageType) error {
switch imageType {
case ImageTypeWEBP:
vipsCommand = exec.Command("vips", "webpsave", "--strip", "--reduction-effort", "4", "--Q", "50", original, newPath)
case ImageTypeAVIF:
vipsCommand = exec.Command("vips", "heifsave", "--strip", "--compression", "av1", "--Q", "50", original, newPath)
case ImageTypeJPEG:
vipsCommand = exec.Command("vips", "jpegsave", "--strip", "--Q", "50", "--optimize-coding", "--optimize-scans", "--trellis-quant", "--quant-table", "3", original, newPath)
}
Expand Down
2 changes: 0 additions & 2 deletions views/partials/preview-image.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{{ $avif := printf "/api/style/preview/%d.avif" .ID }}
{{ $webp := printf "/api/style/preview/%d.webp" .ID }}
{{ if .Preview }}
<picture>
<source srcset="{{ $avif }}" type="image/avif">
<source srcset="{{ $webp }}" type="image/webp">
<img src="/api/style/preview/{{ .ID }}.jpeg"
alt="{{ .Name }} screenshot"
Expand Down

0 comments on commit 9e13023

Please sign in to comment.