|
@@ -5,7 +5,6 @@
|
|
|
[](https://coveralls.io/github/disintegration/imaging?branch=master)
|
|
|
|
|
|
Package imaging provides basic image manipulation functions (resize, rotate, flip, crop, etc.).
|
|
|
-This package is based on the standard Go image package and works best along with it.
|
|
|
|
|
|
Image manipulation functions provided by the package take any image type
|
|
|
that implements `image.Image` interface as an input, and return a new image of
|
|
@@ -56,9 +55,9 @@ The full list of supported filters: NearestNeighbor, Box, Linear, Hermite, Mitc
|
|
|
|
|
|
The original image.
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
-The same image resized from 512x512px to 128x128px using different resampling filters.
|
|
|
+The same image resized from 600x400px to 150x100px using different resampling filters.
|
|
|
From faster (lower quality) to slower (higher quality):
|
|
|
|
|
|
Filter | Resize result
|
|
@@ -79,7 +78,7 @@ Sigma parameter allows to control the strength of the blurring effect.
|
|
|
|
|
|
Original image | Sigma = 0.5 | Sigma = 1.5
|
|
|
-----------------------------------|----------------------------------------|---------------------------------------
|
|
|
- |  | 
|
|
|
+ |  | 
|
|
|
|
|
|
### Sharpening
|
|
|
|
|
@@ -91,7 +90,7 @@ dstImage := imaging.Sharpen(srcImage, 0.5)
|
|
|
|
|
|
Original image | Sigma = 0.5 | Sigma = 1.5
|
|
|
-----------------------------------|-------------------------------------------|------------------------------------------
|
|
|
- |  | 
|
|
|
+ |  | 
|
|
|
|
|
|
### Gamma correction
|
|
|
|
|
@@ -101,7 +100,7 @@ dstImage := imaging.AdjustGamma(srcImage, 0.75)
|
|
|
|
|
|
Original image | Gamma = 0.75 | Gamma = 1.25
|
|
|
-----------------------------------|------------------------------------------|-----------------------------------------
|
|
|
- |  | 
|
|
|
+ |  | 
|
|
|
|
|
|
### Contrast adjustment
|
|
|
|
|
@@ -109,9 +108,9 @@ Original image | Gamma = 0.75 |
|
|
|
dstImage := imaging.AdjustContrast(srcImage, 20)
|
|
|
```
|
|
|
|
|
|
-Original image | Contrast = 10 | Contrast = -10
|
|
|
+Original image | Contrast = 15 | Contrast = -15
|
|
|
-----------------------------------|--------------------------------------------|-------------------------------------------
|
|
|
- |  | 
|
|
|
+ |  | 
|
|
|
|
|
|
### Brightness adjustment
|
|
|
|
|
@@ -121,7 +120,7 @@ dstImage := imaging.AdjustBrightness(srcImage, 20)
|
|
|
|
|
|
Original image | Brightness = 10 | Brightness = -10
|
|
|
-----------------------------------|----------------------------------------------|---------------------------------------------
|
|
|
- |  | 
|
|
|
+ |  | 
|
|
|
|
|
|
## Example code
|
|
|
|
|
@@ -137,20 +136,20 @@ import (
|
|
|
)
|
|
|
|
|
|
func main() {
|
|
|
- // Open the test image.
|
|
|
- src, err := imaging.Open("testdata/lena_512.png")
|
|
|
+ // Open a test image.
|
|
|
+ src, err := imaging.Open("testdata/flowers.png")
|
|
|
if err != nil {
|
|
|
log.Fatalf("Open failed: %v", err)
|
|
|
}
|
|
|
|
|
|
- // Crop the original image to 350x350px size using the center anchor.
|
|
|
- src = imaging.CropAnchor(src, 350, 350, imaging.Center)
|
|
|
+ // Crop the original image to 300x300px size using the center anchor.
|
|
|
+ src = imaging.CropAnchor(src, 300, 300, imaging.Center)
|
|
|
|
|
|
- // Resize the cropped image to width = 256px preserving the aspect ratio.
|
|
|
- src = imaging.Resize(src, 256, 0, imaging.Lanczos)
|
|
|
+ // Resize the cropped image to width = 200px preserving the aspect ratio.
|
|
|
+ src = imaging.Resize(src, 200, 0, imaging.Lanczos)
|
|
|
|
|
|
// Create a blurred version of the image.
|
|
|
- img1 := imaging.Blur(src, 2)
|
|
|
+ img1 := imaging.Blur(src, 5)
|
|
|
|
|
|
// Create a grayscale version of the image with higher contrast and sharpness.
|
|
|
img2 := imaging.Grayscale(src)
|
|
@@ -172,13 +171,13 @@ func main() {
|
|
|
)
|
|
|
|
|
|
// Create a new image and paste the four produced images into it.
|
|
|
- dst := imaging.New(512, 512, color.NRGBA{0, 0, 0, 0})
|
|
|
+ dst := imaging.New(400, 400, color.NRGBA{0, 0, 0, 0})
|
|
|
dst = imaging.Paste(dst, img1, image.Pt(0, 0))
|
|
|
- dst = imaging.Paste(dst, img2, image.Pt(0, 256))
|
|
|
- dst = imaging.Paste(dst, img3, image.Pt(256, 0))
|
|
|
- dst = imaging.Paste(dst, img4, image.Pt(256, 256))
|
|
|
+ dst = imaging.Paste(dst, img2, image.Pt(0, 200))
|
|
|
+ dst = imaging.Paste(dst, img3, image.Pt(200, 0))
|
|
|
+ dst = imaging.Paste(dst, img4, image.Pt(200, 200))
|
|
|
|
|
|
- // Save the resulting image using JPEG format.
|
|
|
+ // Save the resulting image as JPEG.
|
|
|
err = imaging.Save(dst, "testdata/out_example.jpg")
|
|
|
if err != nil {
|
|
|
log.Fatalf("Save failed: %v", err)
|