Skip to content

Commit

Permalink
Merge branch 'master' into animated-gif-support
Browse files Browse the repository at this point in the history
# Conflicts:
#	vips/image.go
  • Loading branch information
elad laufer committed Jan 14, 2022
2 parents 8fdb029 + feda021 commit 164901c
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 @@ -1718,3 +1718,25 @@ func (r *ImageRef) multiPageNotSupported() error {

return nil
}

// 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 164901c

Please sign in to comment.