Make resize point same as resize to ensure seamless images
This commit is contained in:
parent
ff90aa1f5f
commit
89260f0979
1
main.go
1
main.go
|
@ -96,7 +96,6 @@ func serveMarkdown(w http.ResponseWriter, r *http.Request, paths ...string) {
|
|||
pathDir = pathDir[:lastSlash]
|
||||
}
|
||||
// Markdown uses the path to generate the correct paths for resized images
|
||||
log.Print(paths[i], "->", pathDir)
|
||||
html := Markdown(b, pathDir)
|
||||
w.Write(html)
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ package main
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
|
@ -33,7 +32,6 @@ import (
|
|||
|
||||
// Markdown renders GitHub Flavored Markdown text.
|
||||
func Markdown(text []byte, path string) []byte {
|
||||
log.Print("markdown " + path)
|
||||
const htmlFlags = 0
|
||||
renderer := &renderer{
|
||||
Html: blackfriday.HtmlRenderer(htmlFlags, "", "").(*blackfriday.Html), path: path}
|
||||
|
@ -120,7 +118,7 @@ func (r *renderer) Image(out *bytes.Buffer, link []byte, title []byte, alt []byt
|
|||
writeSource := func() {
|
||||
out.WriteString("<source srcset=\"")
|
||||
attrEscape(out, link)
|
||||
out.WriteString("\" media=\"(min-width: 1024px)\">")
|
||||
out.WriteString("\" media=\"(min-width: 800px)\">")
|
||||
}
|
||||
// link to outside of this website
|
||||
if bytes.HasPrefix(link, []byte("http")) {
|
||||
|
|
|
@ -39,9 +39,10 @@ func Resize(maxWidth uint, h http.Handler) http.Handler {
|
|||
rw.Write([]byte("error while decoding png: " + err.Error()))
|
||||
return
|
||||
}
|
||||
resizedImage := resize.Thumbnail(maxWidth, 0, image, resize.Lanczos3)
|
||||
resizedImage := resize.Thumbnail(2*maxWidth, 100000, image, resize.NearestNeighbor)
|
||||
resizedBuf := new(bytes.Buffer)
|
||||
if encodeErr := png.Encode(resizedBuf, resizedImage); encodeErr != nil {
|
||||
encoder := png.Encoder{CompressionLevel: png.BestCompression}
|
||||
if encodeErr := encoder.Encode(resizedBuf, resizedImage); encodeErr != nil {
|
||||
rw.WriteHeader(501)
|
||||
rw.Write([]byte("error while encoding png: " + err.Error()))
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue