Giter VIP home page Giter VIP logo

Comments (3)

bikedel avatar bikedel commented on May 25, 2024

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

}

from image-viewer.

Palexer avatar Palexer commented on May 25, 2024

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.

from image-viewer.

bikedel avatar bikedel commented on May 25, 2024

from image-viewer.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.