Closed Palexer closed 3 years ago
a 10 minute job for you
add your zoom in out buttons that sets a zoom variable that calls the zoom function
To zoom in apply a crop filter
.....
excuse the very messy code below and the very poor implementation - How would you do it?
in img.go I added Zoom int to the Img struct and the functions below
func (a *App) zoomImageIn() { if a.img.OriginalImage == nil { return }
fmt.Println("image bounds :", a.img.OriginalImage.Bounds())
src := a.img.OriginalImage
fmt.Println("image bounds W:", src.Bounds().Dx())
fmt.Println("image bounds W:", src.Bounds().Dy())
my_width := src.Bounds().Dx() - a.img.Zoom
my_height := src.Bounds().Dy() - a.img.Zoom
if a.img.Zoom < my_width {
a.img.Zoom += 10
}
g := gift.New(
gift.Crop(image.Rect(a.img.Zoom, a.img.Zoom, my_width, my_height)),
)
dst := image.NewRGBA(g.Bounds(src.Bounds()))
g.Draw(dst, src)
// show new image
a.image.Image = dst
a.image.Refresh()
}
func (a *App) zoomImageOut() { if a.img.OriginalImage == nil { return } if a.img.Zoom > 0 { a.img.Zoom -= 10 }
src := a.img.OriginalImage
my_width := src.Bounds().Dx() - a.img.Zoom
my_height := src.Bounds().Dy() - a.img.Zoom
g := gift.New(
gift.Crop(image.Rect(a.img.Zoom, a.img.Zoom, my_width, my_height)),
)
dst := image.NewRGBA(g.Bounds(src.Bounds()))
g.Draw(dst, src)
// show new image
a.image.Image = dst
a.image.Refresh()
}
Well, I think it's alright. I was working on an implementation too, but I didn't finish it yet. So I took yours and edited a bit and added buttons and keyboard shortcuts for the functions as well as a function to reset the zoom to 100%. (see 3938ac6 for the details) I think we can close this issue now.
ok sorry mine was a rough job I would have thought it better to apply the zoom to the edited image? also the zoom int would be better applied to the image as a % so that it would work the same for big and small images
On 2021 Apr8, at 21:07, Palexer @.***> wrote:
Well, I think it's alright. I was working on an implementation too, but I didn't finish it yet. So I took yours and edited a bit and added buttons and keyboard shortcuts for the functions as well as a function to reset the zoom to 100%. (see 3938ac6 https://github.com/Palexer/image-viewer/commit/3938ac6d4440642d7a79f1933ea1d58ec30e33d2 for the details) I think we can close this issue now.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Palexer/image-viewer/issues/9#issuecomment-816074497, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD6QUM42GUJBQXNUXG7YL6DTHX5GXANCNFSM4ZX3476A.
It would be great to have a zoom feature with either a slider or a plus and a minus button.