todo image type based on form value

This commit is contained in:
Antoni Sawicki 2024-07-02 02:35:48 -07:00
parent 0e3192b69f
commit 5ed55c387c

3
txt.go
View File

@ -116,6 +116,7 @@ func (t *astTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
link.Destination = append([]byte("?t=txt&url="), link.Destination...) link.Destination = append([]byte("?t=txt&url="), link.Destination...)
} }
if img, ok := n.(*ast.Image); ok && entering { if img, ok := n.(*ast.Image); ok && entering {
// TODO: dynamic extension based on form value
id := fmt.Sprintf("txt%05d.gif", rand.Intn(99999)) // BUG: atomic.AddInt64 or something that ever increases - time based? id := fmt.Sprintf("txt%05d.gif", rand.Intn(99999)) // BUG: atomic.AddInt64 or something that ever increases - time based?
err := grabImage(id, string(img.Destination)) // TODO: use goroutines with waitgroup err := grabImage(id, string(img.Destination)) // TODO: use goroutines with waitgroup
if err != nil { if err != nil {
@ -175,6 +176,7 @@ func imgServerZ(w http.ResponseWriter, r *http.Request) {
w.(http.Flusher).Flush() w.(http.Flusher).Flush()
} }
// TODO set JPG/GIF/PNG type based on form...
func smallGif(src []byte) ([]byte, error) { func smallGif(src []byte) ([]byte, error) {
t := http.DetectContentType(src) t := http.DetectContentType(src)
var err error var err error
@ -197,6 +199,7 @@ func smallGif(src []byte) ([]byte, error) {
img = resize.Thumbnail(uint(*txtImgSize), uint(*txtImgSize), img, resize.NearestNeighbor) img = resize.Thumbnail(uint(*txtImgSize), uint(*txtImgSize), img, resize.NearestNeighbor)
var gifBuf bytes.Buffer var gifBuf bytes.Buffer
err = gif.Encode(&gifBuf, gifPalette(img, 216), &gif.Options{}) err = gif.Encode(&gifBuf, gifPalette(img, 216), &gif.Options{})
//err =jpeg.Encode(&gifBuf, img, &jpeg.Options{Quality: 50})
if err != nil { if err != nil {
return nil, fmt.Errorf("gif encode problem: %v", err) return nil, fmt.Errorf("gif encode problem: %v", err)
} }