Replace oneofone with imaging for image resize

This commit is contained in:
Balakrishnan Balasubramanian 2024-08-09 14:21:45 -04:00
parent 014c180a1e
commit b4d58817a5
4 changed files with 7 additions and 11 deletions

View File

@ -11,7 +11,6 @@ import (
"io/fs"
"github.com/disintegration/imaging"
"go.oneofone.dev/resize"
)
type Dimension struct {
@ -65,13 +64,13 @@ func Make(req *Request, source fs.FS, output io.Writer) error {
}
destRect := FrameTranslate(req.Aspect, req.Dimension, photo.Frame).ToImgRect()
resizedImg := resize.Resize(uint(destRect.Dx()), uint(destRect.Dy()), croppedImage, resize.Lanczos3)
resizedImg := imaging.Resize(croppedImage, destRect.Dx(), destRect.Dy(), imaging.Lanczos)
draw.Draw(canvas, destRect, resizedImg, image.Point{0, 0}, draw.Src)
}
var opt jpeg.Options
opt.Quality = 100
return jpeg.Encode(output, canvas, &opt)
return jpeg.Encode(output, canvas, &jpeg.Options{
Quality: 100,
})
}
func FrameTranslate(resolution Dimension, frameSize Dimension, frame Rectangle) Rectangle {

1
go.mod
View File

@ -5,7 +5,6 @@ go 1.22
require (
github.com/disintegration/imaging v1.6.2
go.balki.me/anyhttp v0.3.0
go.oneofone.dev/resize v1.0.1
)
require golang.org/x/image v0.1.0 // indirect

2
go.sum
View File

@ -3,8 +3,6 @@ github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44am
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/go.mod h1:JhfekOIjgVODoVqUCficjpIgmB3wwlB7jhN0eN2EZ/s=
go.oneofone.dev/resize v1.0.1 h1:HjpVar/4pxMGrjO44ThaMX1Q5UOBw0KxzbxxRDZPQuA=
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-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=

View File

@ -43,7 +43,7 @@ function main() {
loadPhotosBtn.onclick = () => loadPhotos()
makeCollageBtn.onclick = () => gotoCollage()
/** @type HTMLImageElement[] */
/** @type HTMLCollectionOf<HTMLImageElement> */
const selectedPhotos = selectedPhotosDiv.getElementsByTagName("img")
for (const img of selectedPhotos) {
img.onclick = () => {
@ -110,7 +110,7 @@ function loadPhotos() {
albumPhotosDiv.appendChild(img)
}
/** @type HTMLImageElement[] */
/** @type HTMLCollectionOf<HTMLImageElement> */
const photoImgs = albumPhotosDiv.children
for(const photo of photoImgs) {
photo.onclick = () => {
@ -124,7 +124,7 @@ function loadPhotos() {
}
function gotoCollage() {
/** @type HTMLImageElement[] */
/** @type HTMLCollectionOf<HTMLImageElement> */
const selectedPhotos = selectedPhotosDiv.getElementsByTagName("img")
/** @type String[] */
const photoUrls = [];