Compare commits

..

2 Commits

5 changed files with 12 additions and 7 deletions

View File

@ -10,6 +10,7 @@ import (
"io" "io"
"io/fs" "io/fs"
"github.com/disintegration/imaging"
"go.oneofone.dev/resize" "go.oneofone.dev/resize"
) )
@ -102,6 +103,6 @@ func GetImage(source fs.FS, imageName string) (image.Image, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
img, _, err := image.Decode(imgF) img, err := imaging.Decode(imgF, imaging.AutoOrientation(true))
return img, err return img, err
} }

1
go.mod
View File

@ -3,6 +3,7 @@ module go.balki.me/collage-maker
go 1.22 go 1.22
require ( require (
github.com/disintegration/imaging v1.6.2
go.balki.me/anyhttp v0.3.0 go.balki.me/anyhttp v0.3.0
go.oneofone.dev/resize v1.0.1 go.oneofone.dev/resize v1.0.1
) )

3
go.sum
View File

@ -1,3 +1,5 @@
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.balki.me/anyhttp v0.3.0 h1:WtBQ0rnkg567sX/O4ij/+qBbdCIUt5VURSe718sITBY= go.balki.me/anyhttp v0.3.0 h1:WtBQ0rnkg567sX/O4ij/+qBbdCIUt5VURSe718sITBY=
go.balki.me/anyhttp v0.3.0/go.mod h1:JhfekOIjgVODoVqUCficjpIgmB3wwlB7jhN0eN2EZ/s= go.balki.me/anyhttp v0.3.0/go.mod h1:JhfekOIjgVODoVqUCficjpIgmB3wwlB7jhN0eN2EZ/s=
@ -5,6 +7,7 @@ go.oneofone.dev/resize v1.0.1 h1:HjpVar/4pxMGrjO44ThaMX1Q5UOBw0KxzbxxRDZPQuA=
go.oneofone.dev/resize v1.0.1/go.mod h1:zGFmn7q4EUZVlnDmxqf+b0mWpxsTt0MH2yx6ng8tpq0= go.oneofone.dev/resize v1.0.1/go.mod h1:zGFmn7q4EUZVlnDmxqf+b0mWpxsTt0MH2yx6ng8tpq0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.1.0 h1:r8Oj8ZA2Xy12/b5KZYj3tuv7NG/fBz3TwQVvpJ9l8Rk= golang.org/x/image v0.1.0 h1:r8Oj8ZA2Xy12/b5KZYj3tuv7NG/fBz3TwQVvpJ9l8Rk=
golang.org/x/image v0.1.0/go.mod h1:iyPr49SD/G/TBxYVB/9RRtGUT5eNbo2u4NamWeQcD5c= golang.org/x/image v0.1.0/go.mod h1:iyPr49SD/G/TBxYVB/9RRtGUT5eNbo2u4NamWeQcD5c=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=

View File

@ -24,7 +24,6 @@ import (
) )
var ( var (
imagesDir string
collageDir string collageDir string
photosDir string photosDir string
devMode bool devMode bool
@ -41,7 +40,6 @@ var (
func main() { func main() {
var ppURL string var ppURL string
flag.StringVar(&imagesDir, "images-dir", "images", "Sets the images dir")
flag.StringVar(&collageDir, "collages-dir", "collages", "Sets the collages dir") flag.StringVar(&collageDir, "collages-dir", "collages", "Sets the collages dir")
flag.StringVar(&photosDir, "photos-dir", "photos", "Cache directory for downloaded photos") flag.StringVar(&photosDir, "photos-dir", "photos", "Cache directory for downloaded photos")
flag.BoolVar(&devMode, "dev", false, "Serve local assets during development") flag.BoolVar(&devMode, "dev", false, "Serve local assets during development")
@ -59,8 +57,7 @@ func main() {
return photoPrismURL return photoPrismURL
}() }()
collageNameGen = NewNameGen() collageNameGen = NewNameGen()
imagesDirFs = os.DirFS(imagesDir) imagesDirFs = os.DirFS(photosDir)
imagesURLPath := "images"
collagesPath := "collages" collagesPath := "collages"
photosPath := "photos" photosPath := "photos"
@ -69,7 +66,6 @@ func main() {
http.Handle("/"+path+"/", http.StripPrefix("/"+path, httpFileServer)) http.Handle("/"+path+"/", http.StripPrefix("/"+path, httpFileServer))
} }
addFileServer(imagesURLPath, imagesDir)
addFileServer(collagesPath, collageDir) addFileServer(collagesPath, collageDir)
addFileServer(photosPath, photosDir) addFileServer(photosPath, photosDir)

View File

@ -148,8 +148,12 @@ function snap() {
const fsx = elem.offsetLeft - col const fsx = elem.offsetLeft - col
const fsy = elem.offsetTop - cot const fsy = elem.offsetTop - cot
const [sx, sy, ex, ey] = cpie.get().points; const [sx, sy, ex, ey] = cpie.get().points;
const imageFile = (() => {
const u = new URL(elem.dataset.collageImageUrl)
return u.pathname.slice("/photos/".length)
})();
const photo = { const photo = {
image: elem.dataset.collageImageUrl.slice("images/".length), image: imageFile,
crop: { crop: {
start: { start: {
x: parseInt(sx), x: parseInt(sx),