Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom #9

Closed
Palexer opened this issue Mar 24, 2021 · 3 comments
Closed

Zoom #9

Palexer opened this issue Mar 24, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@Palexer
Copy link
Owner

Palexer commented Mar 24, 2021

It would be great to have a zoom feature with either a slider or a plus and a minus button.

@Palexer Palexer added the enhancement New feature or request label Mar 24, 2021
@bikedel
Copy link

bikedel commented Apr 4, 2021

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()

}

@Palexer
Copy link
Owner Author

Palexer commented Apr 8, 2021

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.

@Palexer Palexer closed this as completed Apr 8, 2021
@bikedel
Copy link

bikedel commented Apr 8, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants