nfnt / resize

Pure golang image resizing
ISC License
3.02k stars 321 forks source link

Dst pixel coordinate fix #29

Closed disintegration closed 9 years ago

disintegration commented 9 years ago

Hi, I believe pixel position calculation isn't quite correct. Here's a demo:

package main

import (
    "image"
    "image/png"
    "os"

    "github.com/nfnt/resize"
)

func main() {
    checkers := image.NewGray(image.Rect(0, 0, 4, 4))
    checkers.Pix = []uint8{
        255, 0, 255, 0,
        0, 255, 0, 255,
        255, 0, 255, 0,
        0, 255, 0, 255,
    }
    dst := resize.Resize(100, 100, checkers, resize.NearestNeighbor)
    SaveImage(dst, "test.png")
}

func SaveImage(img image.Image, f string) {
    out, err := os.Create(f)
    if err != nil {
        panic(err)
    }
    defer out.Close()
    png.Encode(out, img)
}

Expected result: test2

Actual result: test

The proposed change fixes the issue.

nfnt commented 9 years ago

Thanks for the bug fix!