Skip to content

Commit

Permalink
Merge branch 'davidbyttow:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Elad-Laufer authored Jan 14, 2022
2 parents 73526fa + 423eb69 commit feda021
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions vips/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -1594,3 +1594,25 @@ const (
CodingLABQ Coding = C.VIPS_CODING_LABQ
CodingRAD Coding = C.VIPS_CODING_RAD
)

// Pixelate applies a simple pixelate filter to the image
func Pixelate(imageRef *ImageRef, factor float64) (err error) {
if factor < 1 {
return errors.New("factor must be greater then 1")
}

width := imageRef.Width()
height := imageRef.Height()

if err = imageRef.Resize(1/factor, KernelAuto); err != nil {
return
}

hScale := float64(width) / float64(imageRef.Width())
vScale := float64(height) / float64(imageRef.Height())
if err = imageRef.ResizeWithVScale(hScale, vScale, KernelNearest); err != nil {
return
}

return
}
8 changes: 8 additions & 0 deletions vips/image_golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,14 @@ func TestImage_QuantTable(t *testing.T) {
)
}

func TestImage_Pixelate(t *testing.T) {
goldenTest(t, resources+"jpg-24bit-icc-iec.jpg",
func(img *ImageRef) error {
return Pixelate(img, 24)
},
nil, nil)
}

func testWebpOptimizeIccProfile(t *testing.T, exportParams *WebpExportParams) []byte {
return goldenTest(t, resources+"has-icc-profile.png",
func(img *ImageRef) error {
Expand Down

0 comments on commit feda021

Please sign in to comment.