merging all related stuff here
This commit is contained in:
48
http/blank/blank.go
Normal file
48
http/blank/blank.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package blank
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
|
||||
"git.nkpl.cc/twocookedfaggots/imageutils"
|
||||
)
|
||||
|
||||
type blank struct {
|
||||
image.Image
|
||||
color.Color
|
||||
imageutils.Side
|
||||
}
|
||||
|
||||
func (b blank) ColorModel() color.Model { return b.Image.ColorModel() }
|
||||
|
||||
func (b blank) Bounds() image.Rectangle {
|
||||
rect := image.Rectangle{}
|
||||
switch b.Side {
|
||||
case imageutils.Left:
|
||||
fallthrough
|
||||
case imageutils.Right:
|
||||
rect = image.Rectangle{
|
||||
image.ZP,
|
||||
image.Point{
|
||||
1, b.Image.Bounds().Dy(),
|
||||
},
|
||||
}
|
||||
case imageutils.Up:
|
||||
fallthrough
|
||||
case imageutils.Down:
|
||||
rect = image.Rectangle{
|
||||
image.ZP,
|
||||
image.Point{
|
||||
b.Image.Bounds().Dx(), 1,
|
||||
},
|
||||
}
|
||||
}
|
||||
return rect
|
||||
}
|
||||
|
||||
func (b blank) At(x, y int) color.Color { return b.Color }
|
||||
|
||||
func Blank(img image.Image, clr color.Color, side imageutils.Side) image.Image {
|
||||
return imageutils.Concat(img, blank{img, clr, side}, side)
|
||||
}
|
||||
@@ -10,12 +10,15 @@ type imageTransform struct {
|
||||
TransformFunc func(image.Image) image.Image
|
||||
}
|
||||
|
||||
type BlankFill struct {
|
||||
}
|
||||
|
||||
func (t imageTransform) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
func indexHTML(w http.ResponseWriter, r *http.Request) {
|
||||
f, err := os.Open("index.html")
|
||||
f, err := os.Open("")
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
log.Fatalln("error opening file:", err)
|
||||
|
||||
33
http/test.go
Normal file
33
http/test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
//go:build ignore
|
||||
package main
|
||||
|
||||
import "git.nkpl.cc/twocookedfaggots/imageutils/http/blank"
|
||||
|
||||
func BlankFillWhiteUp(img image.Image) image.Image {
|
||||
for i := 0; i < img.Bounds().Dx(); i++ {
|
||||
img = blank.Blank(img, color.White, Up)
|
||||
}
|
||||
return img
|
||||
}
|
||||
|
||||
func ProcessImageStdio(f func(image.Image) image.Image) error {
|
||||
img, err := png.Decode(os.Stdin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
img = f(img)
|
||||
err := img.Encode(os.Stdout, img)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := ProcessImageStdio(
|
||||
BlankFillWhiteUp,
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user