summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go.mod2
-rw-r--r--go.sum2
-rw-r--r--image.go35
3 files changed, 30 insertions, 9 deletions
diff --git a/go.mod b/go.mod
index 7e1936c..36758d7 100644
--- a/go.mod
+++ b/go.mod
@@ -7,5 +7,5 @@ require (
github.com/bwmarrin/snowflake v0.3.0
github.com/fyne-io/mobile v0.1.3-0.20210412090810-650a3139866a // indirect
github.com/sqweek/dialog v0.0.0-20211002065838-9a201b55ab91
- random.chars.jp/git/image-board v1.3.10
+ random.chars.jp/git/image-board v1.4.0
)
diff --git a/go.sum b/go.sum
index 184c187..5a26a0e 100644
--- a/go.sum
+++ b/go.sum
@@ -462,4 +462,6 @@ random.chars.jp/git/image-board v1.3.9 h1:zclkIQm4Im51EyTMcrGYJTIBHvOG4TEEjfqY2v
random.chars.jp/git/image-board v1.3.9/go.mod h1:fKoOuCTZ+1F4DCciH+fywbzD+go1GXgStZ+OF7hdr8c=
random.chars.jp/git/image-board v1.3.10 h1:aoN5qsHzIuwxcQnWCl56LJQz8pHzi3Stcs9wOwtg/Wk=
random.chars.jp/git/image-board v1.3.10/go.mod h1:fKoOuCTZ+1F4DCciH+fywbzD+go1GXgStZ+OF7hdr8c=
+random.chars.jp/git/image-board v1.4.0 h1:JxRJNczJ5ojIusXAz12mAJD3QF/cjsL0Pxrqs2pI2+Q=
+random.chars.jp/git/image-board v1.4.0/go.mod h1:fKoOuCTZ+1F4DCciH+fywbzD+go1GXgStZ+OF7hdr8c=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
diff --git a/image.go b/image.go
index 1e70f66..94d59f6 100644
--- a/image.go
+++ b/image.go
@@ -1,6 +1,7 @@
package main
import (
+ "bytes"
"errors"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
@@ -8,6 +9,10 @@ import (
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
+ "image"
+ _ "image/gif"
+ "image/jpeg"
+ _ "image/png"
"io"
"log"
"net/url"
@@ -82,6 +87,20 @@ func (i *imageEntry) resource(preview bool) (*fyne.StaticResource, error) {
case true:
if i.preview != nil {
return i.preview, nil
+ } else {
+ if i.file != nil {
+ log.Printf("Making preview from full image of %s.", i.image.Snowflake)
+ if img, _, err := image.Decode(bytes.NewReader(i.file.Content())); err != nil {
+ return nil, err
+ } else {
+ w := bytes.NewBuffer(nil)
+ if err = jpeg.Encode(w, store.MakePreview(img), &jpeg.Options{Quality: 100}); err != nil {
+ return nil, err
+ }
+ i.preview = fyne.NewStaticResource(i.image.Snowflake+"-preview.jpg", w.Bytes())
+ return i.preview, nil
+ }
+ }
}
case false:
if i.file != nil {
@@ -154,8 +173,8 @@ func dropGroupCache(flake string) {
if group, ok := groupCache[flake]; !ok {
return
} else {
- for _, image := range group {
- delete(groupCache, image.Snowflake)
+ for _, img := range group {
+ delete(groupCache, img.Snowflake)
}
}
}
@@ -282,8 +301,8 @@ func makeGallery(images []store.Image) (*fyne.Container, error) {
Width: 128,
Height: 128,
})
- for i, image := range images {
- if err := loadImage(gallery, image); err != nil {
+ for i, img := range images {
+ if err := loadImage(gallery, img); err != nil {
return nil, err
}
go value(float64(i+1) / float64(len(images)))
@@ -710,18 +729,18 @@ func setImage(image store.Image) {
func addImage(path string, reader io.ReadCloser) {
s := time.Now()
- if image, err := remote.ImageAdd(reader); err != nil {
+ if img, err := remote.ImageAdd(reader); err != nil {
log.Printf("Error adding image file %s, %s", path, err)
go dialog.ShowError(err, window)
return
- } else if image.Snowflake == "" {
+ } else if img.Snowflake == "" {
log.Printf("Image %s upload failure.", path)
go dialog.ShowInformation("Image upload failure",
"Wasn't able to upload the image, report this to your system administrator if this keeps happening.", window)
return
} else {
- log.Printf("Uploaded image %s in %s.", image.Snowflake, time.Now().Sub(s))
+ log.Printf("Uploaded image %s in %s.", img.Snowflake, time.Now().Sub(s))
dropPageCache(-1)
- go setImage(image)
+ go setImage(img)
}
}