Closed mesuutt closed 3 years ago
I want to use imaging.Fit without filtering.
To disable filtering use imaging.NearestNeighbor
as the last parameter of the imaging.Fit
function.
Hi @disintegration, thanks for your reply.
I used imaging.NearestNeighbor
but image qualty still poor. Maybe this is not related imaging
but I don't found any issue at code. I want to crop max 640x640 and save.
img, _, err := image.Decode(bytes.NewReader(*fileContentBytes))
if err != nil {
return err
}
thumbnailImg := imaging.Fit(img, 640, 640, imaging.NearestNeighbor)
f, err := os.Create("foo.jpeg")
if err != nil {
return err
}
defer f.Close()
buf := new(bytes.Buffer)
if err := jpeg.Encode(buf, thumbnailImg, &jpeg.Options{Quality:100}); err != nil {
return err
}
_, err = f.Write(*file.Content)
if err != nil {
return err
}
Original Image:
New created image( there are white dots in image):
Are you sure you've attached the right original image? It's already 640 pixels wide so Fit
does essentially nothing.
Here's the code i've used:
package main
import (
"log"
"github.com/disintegration/imaging"
)
func main() {
src, err := imaging.Open("src.jpg")
if err != nil {
log.Fatal(err)
}
dst := imaging.Fit(src, 640, 640, imaging.NearestNeighbor)
if err := imaging.Save(dst, "dst.jpg"); err != nil {
log.Fatal(err)
}
}
And the result:
I believe the original image in your example was larger.
You asked for no-filtering mode, but for this type of image (photography) you won't get a high quality result by disabling filtering, quite the opposite. My recommendation is to use the CatmullRom or Lanczos filter.
Closing the issue. Feel free to reopen if you have any further questions.
I want to use
imaging.Fit
without filtering. When I use.Fit
image quality falling. I want to crop file same as.Fit
without loss qualty. How can I do this?