Giter Club home page Giter Club logo

imaging's Introduction

Imaging

PkgGoDev Build Status Coverage Status Go Report Card

Package imaging provides basic image processing functions (resize, rotate, crop, brightness/contrast adjustments, etc.).

All the image processing functions provided by the package accept any image type that implements image.Image interface as an input, and return a new image of *image.NRGBA type (32bit RGBA colors, non-premultiplied alpha).

Installation

go get -u github.com/disintegration/imaging

Documentation

https://pkg.go.dev/github.com/disintegration/imaging

Usage examples

A few usage examples can be found below. See the documentation for the full list of supported functions.

Image resizing

// Resize srcImage to size = 128x128px using the Lanczos filter.
dstImage128 := imaging.Resize(srcImage, 128, 128, imaging.Lanczos)

// Resize srcImage to width = 800px preserving the aspect ratio.
dstImage800 := imaging.Resize(srcImage, 800, 0, imaging.Lanczos)

// Scale down srcImage to fit the 800x600px bounding box.
dstImageFit := imaging.Fit(srcImage, 800, 600, imaging.Lanczos)

// Resize and crop the srcImage to fill the 100x100px area.
dstImageFill := imaging.Fill(srcImage, 100, 100, imaging.Center, imaging.Lanczos)

Imaging supports image resizing using various resampling filters. The most notable ones:

  • Lanczos - A high-quality resampling filter for photographic images yielding sharp results.
  • CatmullRom - A sharp cubic filter that is faster than Lanczos filter while providing similar results.
  • MitchellNetravali - A cubic filter that produces smoother results with less ringing artifacts than CatmullRom.
  • Linear - Bilinear resampling filter, produces smooth output. Faster than cubic filters.
  • Box - Simple and fast averaging filter appropriate for downscaling. When upscaling it's similar to NearestNeighbor.
  • NearestNeighbor - Fastest resampling filter, no antialiasing.

The full list of supported filters: NearestNeighbor, Box, Linear, Hermite, MitchellNetravali, CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine. Custom filters can be created using ResampleFilter struct.

Resampling filters comparison

Original image:

srcImage

The same image resized from 600x400px to 150x100px using different resampling filters. From faster (lower quality) to slower (higher quality):

Filter Resize result
imaging.NearestNeighbor dstImage
imaging.Linear dstImage
imaging.CatmullRom dstImage
imaging.Lanczos dstImage

Gaussian Blur

dstImage := imaging.Blur(srcImage, 0.5)

Sigma parameter allows to control the strength of the blurring effect.

Original image Sigma = 0.5 Sigma = 1.5
srcImage dstImage dstImage

Sharpening

dstImage := imaging.Sharpen(srcImage, 0.5)

Sharpen uses gaussian function internally. Sigma parameter allows to control the strength of the sharpening effect.

Original image Sigma = 0.5 Sigma = 1.5
srcImage dstImage dstImage

Gamma correction

dstImage := imaging.AdjustGamma(srcImage, 0.75)
Original image Gamma = 0.75 Gamma = 1.25
srcImage dstImage dstImage

Contrast adjustment

dstImage := imaging.AdjustContrast(srcImage, 20)
Original image Contrast = 15 Contrast = -15
srcImage dstImage dstImage

Brightness adjustment

dstImage := imaging.AdjustBrightness(srcImage, 20)
Original image Brightness = 10 Brightness = -10
srcImage dstImage dstImage

Saturation adjustment

dstImage := imaging.AdjustSaturation(srcImage, 20)
Original image Saturation = 30 Saturation = -30
srcImage dstImage dstImage

Hue adjustment

dstImage := imaging.AdjustHue(srcImage, 20)
Original image Hue = 60 Hue = -60
srcImage dstImage dstImage

FAQ

Incorrect image orientation after processing (e.g. an image appears rotated after resizing)

Most probably, the given image contains the EXIF orientation tag. The standard image/* packages do not support loading and saving this kind of information. To fix the issue, try opening images with the AutoOrientation decode option. If this option is set to true, the image orientation is changed after decoding, according to the orientation tag (if present). Here's the example:

img, err := imaging.Open("test.jpg", imaging.AutoOrientation(true))

What's the difference between imaging and gift packages?

imaging is designed to be a lightweight and simple image manipulation package. It provides basic image processing functions and a few helper functions such as Open and Save. It consistently returns *image.NRGBA image type (8 bits per channel, RGBA).

gift supports more advanced image processing, for example, sRGB/Linear color space conversions. It also supports different output image types (e.g. 16 bits per channel) and provides easy-to-use API for chaining multiple processing steps together.

Example code

package main

import (
	"image"
	"image/color"
	"log"

	"github.com/disintegration/imaging"
)

func main() {
	// Open a test image.
	src, err := imaging.Open("testdata/flowers.png")
	if err != nil {
		log.Fatalf("failed to open image: %v", err)
	}

	// 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 = 200px preserving the aspect ratio.
	src = imaging.Resize(src, 200, 0, imaging.Lanczos)

	// Create a blurred version of the image.
	img1 := imaging.Blur(src, 5)

	// Create a grayscale version of the image with higher contrast and sharpness.
	img2 := imaging.Grayscale(src)
	img2 = imaging.AdjustContrast(img2, 20)
	img2 = imaging.Sharpen(img2, 2)

	// Create an inverted version of the image.
	img3 := imaging.Invert(src)

	// Create an embossed version of the image using a convolution filter.
	img4 := imaging.Convolve3x3(
		src,
		[9]float64{
			-1, -1, 0,
			-1, 1, 1,
			0, 1, 1,
		},
		nil,
	)

	// Create a new image and paste the four produced images into it.
	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, 200))
	dst = imaging.Paste(dst, img3, image.Pt(200, 0))
	dst = imaging.Paste(dst, img4, image.Pt(200, 200))

	// Save the resulting image as JPEG.
	err = imaging.Save(dst, "testdata/out_example.jpg")
	if err != nil {
		log.Fatalf("failed to save image: %v", err)
	}
}

Output:

dstImage

imaging's People

Contributors

charlie-collard avatar dherbst avatar disintegration avatar djworth avatar dthadi3 avatar hassansin avatar hjr265 avatar hsn723 avatar j-delaney avatar jasonmoo avatar maestromusica avatar morphar avatar oliverpool avatar orisano avatar richardprior avatar sosiska avatar struffel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imaging's Issues

Does not support animated gif?

Hi,

I'm wondering if this library supports animated gif or if it's a limitation of the Go image library itself.

Do you have information?

Dead simple example, with the source file giphy.gif

package main

import (
    "runtime"

    "github.com/disintegration/imaging"
)

func main() {
    // use all CPU cores for maximum performance
    runtime.GOMAXPROCS(runtime.NumCPU())

    // input files
    img, err := imaging.Open("giphy.gif")
    if err != nil {
        panic(err)
    }
    thumb := imaging.Thumbnail(img, 100, 100, imaging.Lanczos)

    err = imaging.Save(thumb, "dst.gif")
    if err != nil {
        panic(err)
    }
}

RFC : Merge Filters

I would like to suggest an API that would merge all this filters since that have some basic similarities

Current Method

dstImage = imaging.Blur(srcImage, 4.5)
dstImage = imaging.Sharpen(srcImage, 3.0)

Proposed Interface

filter = imaging.Filter(srcImage)
filter.Blur(4.5)
filter.Sharpen( 3.0)

Better Interface

  • Let and Crop , Paste, Overlay support interface Instead
  • Brightness , Contrast , Gamma & Contrast can be filters too
img, err := imaging.Open("src.png")  // Open Image and Return  ImageSrc type  

filter := imaging.Filter(img) // Start Filter
filter.Grayscale()  
filter.Blur(4.5) 
filter.Sharpen( 3.0) 
filter.Brightness(+5)
filter.Contrast(+2)

img.Rotate(90) // Rotate Image 90 degree 
img.PasteCenter(backgroundImage) // Paste Image a new Background 

// Save a thumb copy of image 
thumb , err := img.Thumbnail(100, 100, imaging.CatmullRom) // Return ImageSrc type
thumb.Save("dst_thumb.jpg") // Save Thumb

// Save Final Image 
img.Save("dst.jpg") 

Advantage

  • As it stands , there are to many duplicated codes and this would help reduce it
  • Avoid reading and writing to file especially in very slow disk or IO conditions
  • toNRGBA(img) would be called once
  • Sharpen uses Blur and a simple cache can take place instead of trying to run the blur again
  • image.NewNRGBA does not need to be called multiple times
  • Faster Operation when dealing with multiple filters on single image
  • imaging.Grayscale(srcImage) etc can still be syntactic sugars

Conclusion

Performance can easy be improved when working with multiple images with multiple filters and adjustment on the same images. Its open for improvement and discussion.

What do you think ?

webp image support

Hi,
I wanted to contribute webp encoding/decoding to imaging (very nice library btw)!
However I think webp support was introduced around 1.2 and I seem to have read that you'd rather preserve compatibility with older go versions.

Should I rather write webp support in my own application?

Image Rotated after blur

Hi there,

Images (JPEG) get rotated by 90 degree if blured.

func blurImage(src io.Reader, imgType string) ([]byte, error) {
    /*switch imgType {
    case "jpeg":
        img, err = jpeg.Decode(src)
    case "png":
        img, err = png.Decode(src)
    case "gif":
        img, err = gif.Decode(src)
    default:
        return nil, errors.New("No filetype")
    }*/
    img, imgType, err := image.Decode(src)
    if err != nil {
        return nil, err
    }
    var blurSigma float64
    confBlurSigmaStr := os.Getenv("Blur_Sigma")
    if confBlurSigmaStr == "" {
        blurSigma = 25
    } else {
        blurSigma, err = strconv.ParseFloat(confBlurSigmaStr, 64)
    }
    if err != nil {
        return nil, err
    }
    bluredImg := imaging.Blur(img, blurSigma)
    return encodeImage(bluredImg, imgType)
}

README lacks images

For example, images for resize, fit and thumbnail. Also, for ResampleFilters.

imaging vs gitf

I am getting a bit confused with the 2 packages having a big overlap. Could you please elaborate a bit on wich one should be use ?

The usecase I am having is : resize and crop

Build failed: effects.go:8: gaussianBlurKernel redeclared in this block

Trying to build our service with current git of imaging library and I have following error:

github.com/disintegration/imaging

../../github.com/disintegration/imaging/effects.go:8: gaussianBlurKernel redeclared in this block
previous declaration at ../../github.com/disintegration/imaging/blur.go:8
../../github.com/disintegration/imaging/effects.go:19: Blur redeclared in this block
previous declaration at ../../github.com/disintegration/imaging/blur.go:26
../../github.com/disintegration/imaging/effects.go:40: blurHorizontal redeclared in this block
previous declaration at ../../github.com/disintegration/imaging/blur.go:47
../../github.com/disintegration/imaging/effects.go:94: blurVertical redeclared in this block
previous declaration at ../../github.com/disintegration/imaging/blur.go:101
../../github.com/disintegration/imaging/resize.go:65: Resize redeclared in this block
previous declaration at ../../github.com/disintegration/imaging/resample.go:19
../../github.com/disintegration/imaging/resize.go:116: resizeHorizontal redeclared in this block
previous declaration at ../../github.com/disintegration/imaging/resample.go:69
../../github.com/disintegration/imaging/resize.go:152: resizeVertical redeclared in this block
previous declaration at ../../github.com/disintegration/imaging/resample.go:137
../../github.com/disintegration/imaging/resize.go:191: resizeNearest redeclared in this block
previous declaration at ../../github.com/disintegration/imaging/resample.go:206
../../github.com/disintegration/imaging/resize.go:236: Fit redeclared in this block
previous declaration at ../../github.com/disintegration/imaging/resample.go:251
../../github.com/disintegration/imaging/resize.go:280: Thumbnail redeclared in this block
previous declaration at ../../github.com/disintegration/imaging/resample.go:295
../../github.com/disintegration/imaging/resize.go:280: too many errors

Checkout out 3ab6ec5 revision of this library and it works.

Gray edges on transparent png resizes

Hey, using the following code:

package main

import (
    "log"

   "github.com/disintegration/imaging"
)

func main() {
    src, err := imaging.Open("src.png")
    if err != nil {
        log.Fatal(err)
    }

    dst := imaging.Resize(src, 200, 200, imaging.Lanczos)

    err = imaging.Save(dst, "dst.png")
    if err != nil {
        log.Fatal(err)
    }
}

I'm seeing gray aliasing on the resized image:

Example:

Original:
image

Resized:
dst

Any ideas what I could do to reduce the gray edge?

Strip alpha functionality

Hi,

It would be neat to have a strip-alpha-functionality as an option for saving the image. Currently, PNG's that contains an alpha background and are saved to JPG are having a black background.

thanks,
pepijn

Overlay and Paste not producing images

For starters, I'm running Go 1.1.2 on OS X 10.8.
I'm not sure if this is a problem with me misusing the library, or something not working right in general. I'm trying to take a slice of images cropped images (the cropping works), resize them, and then overlay or paste them in 2 rows, and x columns, based on the size of the slice.

If I try and save the resized image to a file, it saves correctly. If I try and overlay the resized image on a new image, and save that new image, the new image does not save the resized images onto the one new image.

Here's some code to demonstrate what I'm doing.

func StitchImages(images []image.Image) image.Image {
    imageCount := len(images)

    imageWidth := stitchedImageWidth / imageCount * 2
    imageHeight := stitchedImageHeight / 2

    newImage := imaging.New(stitchedImageWidth, stitchedImageHeight, color.NRGBA{255, 0, 0, 255})

    for i := 0; i < imageCount; i++ {
        currImage := images[i]

        x := ((i % (imageCount / 2)) * imageWidth)
        y := 0
        if i >= imageCount/2 {
            y = imageHeight
        }

        croppedImage := CropCenter(currImage)
        resizedImage := imaging.Resize(croppedImage, imageWidth, imageHeight, imaging.CatmullRom)
        imaging.Overlay(newImage, resizedImage, image.Pt(x, y), 1.0)
    }

    return newImage
}

And being invoked from main.go as such:

sourceImage, _ := imaging.Open("NYAN.png")
croppedImage := Stitcher.CropFromBottom(sourceImage)
imagesToStitch := []image.Image{croppedImage, croppedImage, croppedImage, croppedImage, croppedImage, croppedImage, croppedImage, croppedImage}
stitchedImage := Stitcher.StitchImages(imagesToStitch)
imaging.Save(stitchedImage, "NYAN-collaged.png")

Some problem in Thumbnail function.

There is a premise that we must ensure the integrity of image, so I think there is some problem in Thumbnail function that the if condition is reverse.

    if srcAspectRatio > thumbAspectRatio {
        tmp = Resize(img, 0, thumbH, filter)
    } else {
        tmp = Resize(img, thumbW, 0, filter)
    }

Rotate with offset/anchor/origin

Hi,

is it possible to add a function for rotating an image and specify the offset ourself? I've checked the code and it seems the function for this is already there ... Just private ...
This would be a great help.

It's not obvious that this package doesn't carry over EXIF data

I've been using this package to rotate images as I migrate them from my laptop to a server, and I just went crazy trying to figure out why my EXIF data disappeared. It turns out that using this package caused that to happen. I am simply using imaging.Open, imaging.Rotate180, and imaging.Save. It appears that the transformation to an image.NRGBA makes that metadata disappear?

When automating simple tasks like rotation I think it makes sense that one would expect the image's metadata to remain. For example, ImageMagick's convert command line utility does maintain EXIF data when doing a simple rotate. I think this package should include a warning that that's not the case here.

Issue with JPEG encoding?

HIi,

I have a struct called SpriteImage which is defined like this:

type SpriteImage struct {
    dimentions      image.Point
    lastImgPosition image.Point
    sprite          *image.NRGBA
}

In my flow, I first initiate a new such struct:

func NewSpriteImage(width, height int) SpriteImage {
    c := color.RGBA{0xff, 0xff, 0xff, 0xff}
    blankImage := imaging.New(width, height, c)

    return SpriteImage{
        dimentions:      image.Point{X: width, Y: height},
        lastImgPosition: image.Point{X: 0, Y: 0},
        sprite:          blankImage,
    }
}

And then I add images to this SpriteImage like so:

func (s *SpriteImage) AddImage(img image.Image) error {
    imgWidth := img.Bounds().Dx()
    imgHeight := img.Bounds().Dy()

    // Make sure new image will fit into the sprite.
    if imgWidth != s.dimentions.X {
        return fmt.Errorf("image width %d mismatch sprite width %d", imgWidth, s.dimentions.X)
    }

    spriteHeightLeft := s.dimentions.Y - s.lastImgPosition.Y
    if imgHeight > spriteHeightLeft {
        return fmt.Errorf("image height %d won't fit into sprite, sprite free space %d ", imgHeight, s.dimentions.Y)
    }

    // add image to sprite
    s.sprite = imaging.Paste(s.sprite, img, s.lastImgPosition)

    // update next image position within sprite
    s.lastImgPosition = s.lastImgPosition.Add(image.Point{X: 0, Y: imgHeight})

    return nil
}

Eventually, I want to take this SpriteImage and encode it as JPEG. But it doesn't seem to work. The native JPEG Encode function takes up an image, but I have an image.NRGBA. So I'm using github.com/disintegration/imaging lib like so:

func (s SpriteImage) GetBytes() ([]byte, error) {
    var b bytes.Buffer
    w := bufio.NewWriter(&b)

    if s.sprite == nil {
        return nil, fmt.Errorf("sprite is nil")
    }

    if err := imaging.Encode(w, s.sprite, imaging.JPEG); err != nil {
        return nil, err
    }

    return b.Bytes(), nil
}

However is seems that the bytes returned are not in fact JPEG. The native Go JPEG lib will not decode those bytes to a Go image struct. If I try to decode those bytes to image like so:

     m, _, err := image.Decode(reader)
     if err != nil {
        log.Fatal(err)
     }

I'm getting err:

image: unknown format

Any ideas? Thanks!

[Help] What Unit of Measure used in CropCenter

Hi

What's your UOM (mm, inch, px, pt ... ) used in CropCenter. I have a image 25.4X110mm, try to crop 20X110mm in center (both x, y) but can't get result as I wanted,

src, err := imaging.Open(filename)
if err != nil {
	return rslt, err
}

fout := _tp1[0]
if ... {
	//src = imaging.CropAnchor(src, int(PT_(realW)), int(PT_(realH)), imaging.Center) // Crop
	src = imaging.CropCenter(src, int(PT_(realW)), int(PT_(realH)))
	log.Println(int(PT_(realW)), int(PT_(realH)), realW, realH, "cima")
	fout = strings.Replace(fout, fmt.Sprintf(".%s", ext), fmt.Sprintf("N.%s", ext), -1)
	err = imaging.Save(src, fout)
	if err != nil {
	     return rslt, err
        }
}

func PT_(s string) float64 {
	pos, uom := MeasureTuple(s)

	var new_pos float64

	switch strings.ToLower(uom) {
	case "in":
		new_pos = pos * 72.0
	case "inch":
		new_pos = pos * 72.0
	case "cm":
		new_pos = (pos * 10 / 25.4) * 72.0
	case "mm":
		new_pos = (pos / 25.4) * 72.0
	case "pt":
		new_pos = pos
	default:
		new_pos = pos
	}

	return new_pos
}

Rendered JPEG appears rotated.

I have some pictures shot in portrait position coming from my digital camera (Panasonic Lumix) and phone (Samsung S7) which appear rotated after loading, fitting and saving them.
Here is the code:

package main

import (
    "flag"
    "fmt"

    "github.com/disintegration/imaging"
)

func main() {
    filename := flag.String("file", "", "input file")
    flag.Parse()
    if filename == nil {
        panic("missing input file")
    }

    fmt.Println("opening " + *filename)

    img, err := imaging.Open(*filename)
    if err != nil {
        panic(err)
    }

    dst := imaging.Fit(img, 800, 600, imaging.Lanczos)

    if err := imaging.Save(dst, "converted.jpg"); err != nil {
        panic(err)
    }
}

The original is (when downloaded) shown in portrait mode.
original

The converted (probably has all EXIF info scrapped) is shown in neutral mode (guess that's landscape)
converted

cannot paste image with transparent pixels

I cannot figure out how to paste an image with transparent areas into a background image. The code below produces an image where the transparent areas are colored (white if I save it as PNG, or black if I save it as JPEG). Please help.

package main

import (
    "image"
    "image/color"

    "github.com/disintegration/imaging"
)

func main() {
    background := imaging.New(200, 200, color.RGBA{0, 255, 0, 255})
    line := imaging.New(100, 100, color.Transparent)

    for x := 20; x < 80; x++ {
        y := x/3 + 15
        line.Set(x, y, color.RGBA{255, 0, 0, 255})
    }

    result := imaging.Paste(background, line, image.Point{0, 0})

    imaging.Save(result, "test.png")
}

Avoiding regexp in Save()

This may be too insignificant to even mention, but I noticed a little improvement in memory performance of Save() when regexp is not used in it.

I wrote a small benchmark func for it:

func BenchmarkSave(b *testing.B) {
    img, err := Open("mickey.jpg")
    catch(err)

    b.ResetTimer()

    for i := 0; i < b.N; i++ {
        err = Save(img, "mickey.out.jpg")
        catch(err)
    }
}

When I ran it with the current Save() method (with regexp), this is what I got:

BenchmarkSave         50      52964825 ns/op       12308 B/op         80 allocs/op

When I ran it on a modified Save() method (without regexp), this is what I got:

BenchmarkSave         50      51917256 ns/op        4810 B/op          8 allocs/op    

The time-wise performance is almost unchanged. But the memory allocations per invocation is 1/10th of the original number.

The regexp.MatchString() is not really required here, since the switch on format is going to prevent any invalid file extension anyway.

I could send you a pull request making this change if that's okay.

EXIF support ?

Hello,

Is it possible to add EXIF information extractor ? And a bit greedy, I could not find any image library that supports saving original EXIF information after changing images (e.g. resize, rotate...). The encode function of go image library could not handle EXIF. So after you resize or rotate your photos, EXIF will lost in new saved copies.

Svg ?

Am hunting around for a way to convert svg to png, etc using pure g

width or heigth == 0 for imaging.Thumbnail

I started to play with imaging and I very soon stumble on an interesting edge case. imaging.Resize handle the case where width or heigth == 0 in a very intuitive way. There is a check in the code to do the right thing but in imaging.Thumbnail this case is not supported. I can see argument either way so I am wondering if you this this has a bug or a feature.

GOOS=386 on Go 1.5.1 has internal compiler error when cross compiling on OSX El Capitan

After updating to Go 1.5.1 the pkg no longer compiles with GOARCH=386. (Same issue whether GOOS is windows,linux or darwin)

[14:00:30][ruxton@cyclops:imaging] $ brew switch go 1.4.2
Cleaning /usr/local/Cellar/go/1.4.2
Cleaning /usr/local/Cellar/go/1.5.1
3 links created for /usr/local/Cellar/go/1.4.2

(master)
[14:00:31][ruxton@cyclops:imaging] $ go version
go version go1.4.2 darwin/amd64

(master)
[14:00:40][ruxton@cyclops:imaging] $ GOARCH=386 GOOS=windows go build -a

(master)
[14:00:49][ruxton@cyclops:imaging] $ brew switch go 1.5.1
Cleaning /usr/local/Cellar/go/1.4.2
Cleaning /usr/local/Cellar/go/1.5.1
3 links created for /usr/local/Cellar/go/1.5.1

(master)
[14:00:59][ruxton@cyclops:imaging] $ go version
go version go1.5.1 darwin/amd64

(master)
[14:01:03][ruxton@cyclops:imaging] $ GOARCH=386 GOOS=windows go build -a
# github.com/disintegration/imaging
run compiler with -v for register allocation sites
./helpers.go:229: internal compiler error: out of fixed registers

how can I crop the desired size

I want to cut the Image(480×853) to (720 × 370).
so, I run

a := image.Rect(0,0,720,370)
src, _ := imaging.Open("FILE.jpg")
dst := imaging.Resize(src, 720, 0, imaging.Lanczos) 
dst = imaging.Crop(src, a)
imaging.Save(dst, "dst.jpg")

but result is (480 × 370)
how can I cut the image to (720 × 370)

Unsharp Mask

I have been using your code for image resizing mainly, and I would like to apply a unsharp mask. I feel like this may be possible with the tools you have created, but it is unclear to me. Can you explain how to do this, or add a function to do so?

Either way thanks for the code!

Other Consideration

I would like to say well done and keep up the good job. Have you considered the following :

  • Mean
  • Smooth
  • Colorize
  • Sepia
  • Emboss
  • etc

If so what are the timelines like ?

GIF support

Dear Grigory Dryapak,

This is completely awesome open source code project, But it does't support GIF file.

Can you please provide GIF support for this.

Thank you.

Selecting * image.YCbCr instead * image.NRGBA

You use *image.NRGBA the default, but the standard library saves the image in *image.YCbCr. As a result, at least one extra converting image.

I plan to rewrite on the *image.YCbCr, but not anytime soon.

I noticed when working with jpeg, other formats are not looking.

save image with higher quality?

Hello, Grigory, do you know if I can save an image with a DPI (PPI) higher than the standard image library offers? They save at 72 PPI.

Memory leak on 32-bit windows

I use the following function to rotate images. The program keeps calling this function with a set of photos (each with 4-5MB, 3000x4000 size), each call will make the program's memory to increase about 100,000K (monitored from task manager), and after 10 or more times the program exits with "not enough memory" error.

Environment: go 1.3.1 windows 32-bit
I checked with go pprof, the top heap consumption ocurrs in helpers.go(line 27) and clone.go(line 13), transform.go(line 70). It seems "img" variables are not collected by GC in time. I checked with the code and could not find any problem. Is it the problem of go Garbage Collector or of other ?

func rotatePhoto(ip string, dir bool) error {
var rimg image.Image
img, err := imaging.Open(ip)
if err != nil {
return err
}
if dir {
rimg = imaging.Rotate270(img)
} else {
rimg = imaging.Rotate90(img)
}
// save the image to file
err = imaging.Save(rimg, ip)
rimg = nil
if err != nil {
fmt.Println(err)
return err
}
return nil
}

Clarify the difference between imaging and gift

There seems to be an overlap of functionalities provided by github.com/disintegration/imaging and github.com/disintegration/gift: rotate, flip, resize, crop, etc. What package should I use? What's the difference?

Causing a memory leak (and crash) on Google App Engine

I'm trying to use imaging in an App Engine app, and after resizing about 6 images the application shuts down because of excessive memory usage. This usually happens because of goroutines that don't exit, so that might be the case. Is there a way to turn off parallel computation via a flag or option for environments like this? Or we can just make sure that all spawned goroutines always exit cleanly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.