GithubHelp home page GithubHelp logo

vipsimage / vips Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 1.0 755 KB

Vips is a go bind to libvips C API.

Home Page: https://vipsimage.com/vips

License: MIT License

Go 67.04% C 32.96%
vips libvips cgo crop jpeg processing golang image resize png webp crop-image

vips's Introduction

Go Vips

Go Vips is a go bind to libvips C API.

Install

Check if pkg-config is able to find the right libvips include:

pkg-config --cflags --libs vips  

Package 'libffi', required by 'gobject-2.0', not found

# optional, use you libffi lib path  
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"  

Per the security update https://groups.google.com/forum/#!topic/golang-announce/X7N1mvntnoU you may need whitelist the -Xpreprocessor flag in your environment.

export CGO_CFLAGS_ALLOW='-Xpreprocessor'  

examples

func main() {
	img := vips.NewFromFile("./images/Landscape_2.jpg")
	wm := vips.NewFromFile("./images/away.webp")

	err := wm.ThumbnailImage(200)
	if err != nil {
		panic(err)
	}

	err = wm.Resize(float64(img.Width()) / float64(wm.Width()))
	if err != nil {
		panic(err)
	}

	err = wm.Rotate(30)
	if err != nil {
		panic(err)
	}

	err = wm.Replicate(img.Width()/wm.Width()+1, img.Height()/wm.Height()+1)
	if err != nil {
		panic(err)
	}
	img.Replicate(2, 2)

	fmt.Println(img.Height(), img.Width())

	imgCopy, err := img.Copy()
	if err != nil {
		panic(err)
	}
	fmt.Println(imgCopy.Width())

	err = img.Save2file("out.png")
	if err != nil {
		panic(err)
	}
}

Features

conversion

  • Copy: Copy an image, optionally modifying the header.
  • Replicate: repeats an image many times.
  • Gravity: place in within an image of size width by height at a certain gravity.
  • Composite2: composite overlay on top of base with mode .
  • GetAngle: examine the metadata on im and return the VipsAngle
  • AutoRot: look at the image metadata and rotate the image to make it upright.
  • Embed: Embed *Image within an image of size width by height at position x , y .
  • ExtractArea: extract an area from an image. The area must fit within *Image.
  • Crop: Crop a synonym for ExtractArea
  • Flip: Flip an image left-right or up-down.
  • Grid: Grid chop a tall thin image up into a set of tiles, lay the tiles out in a grid.
  • Scale: Scale search the image for the maximum and minimum value
  • SubSample: SubSample an image by an integer fraction. This is fast, nearest-neighbour shrink.
  • Zoom: Zoom an image by repeating pixels. This is fast nearest-neighbour zoom.
  • Wrap: Wrap slice an image up and move the segments
  • ExtractBand: SmartCrop crop an image down to a specified width and height by removing boring parts.

create

  • Black: Black make a black unsigned char image of a specified size.
  • Xyz: Xyz Create a two-band uint32 image where the elements in the first band have the value of their x coordinate and elements in the second band have their y coordinate.
  • Grey: Grey create a one-band float image with the left-most column zero and the right-most 1.
  • GaussMat: GaussMat Creates a circularly symmetric Gaussian image of radius sigma.
  • LogMat: LogMat creates a circularly symmetric Laplacian of Gaussian mask of radius sigma.
  • Text: Text draw the string text to an image.
  • GaussNoise: GaussNoise make a one band float image of gaussian noise with the specified distribution.
  • Eye: Eye create a test pattern with increasing spatial frequence in X and amplitude in Y.
  • Sines: Sines creates a float one band image of the a sine waveform in two dimensions.
  • Zone: Zone create a one-band image of a zone plate.
  • Identity: Identity creates an identity lookup table.
  • BuildLut: BuildLut this operation builds a lookup table from a set of points.
  • InvertLut: InvertLut given a mask of target values and real values, generate a LUT which will map reals to targets.
  • ToneLut: ToneLut generates a tone curve for the adjustment of image levels.
  • MaskIdeal: MaskIdeal Make an ideal high- or low-pass filter.
  • MaskIdealRing: MaskIdealRing make an ideal ring-pass or ring-reject filter.
  • MaskIdealBand: MaskIdealBand make an ideal band-pass or band-reject filter.
  • MaskButterWorth: MaskButterWorth make an butterworth high- or low-pass filter.
  • MaskButterWorthRing: MaskButterWorthRing Make a butterworth ring-pass or ring-reject filter.
  • MaskButterWorthBand: MaskButterWorthBand make an butterworth band-pass or band-reject filter
  • MaskGaussian: MaskGaussian Make a gaussian high- or low-pass filter.
  • MaskGaussianRing: MaskGaussianRing Make a gaussian ring-pass or ring-reject filter.
  • MaskGaussianBand: MaskGaussianBand Make a gaussian band-pass or band-reject filter.
  • MaskFractal: MaskFractal operation should be used to create fractal images by filtering the power spectrum of Gaussian white noise
  • FractSurf: FractSurf Generate an image of size width by height and fractal dimension fractalDimension.
  • Worley: Worley create a one-band float image of Worley noise.
  • Perlin: Perlin create a one-band float image of Perlin noise.

draw

  • DrawRect: DrawRect paint pixels within left , top , width , height in image with ink.
  • DrawRect1: DrawRect1 as DrawRect, but just take a single float64 for ink.
  • DrawPoint: DrawPoint draw a single pixel at x, y.
  • DrawPoint1: DrawPoint1 as DrawPoint, but just take a single float64 for ink.
  • DrawImage: DrawImage draw sub on top of image at position x, y.
  • DrawMask: DrawMask draw mask on the image. mask is a monochrome 8-bit image with 0/255 for transparent or ink coloured points.
  • DrawMask1: DrawMask1 as DrawMask, but just take a single float64 for ink.
  • DrawLine: DrawLine draws a 1-pixel-wide line on an image.
  • DrawLine1: DrawLine1 as DrawLine, but just take a single double for ink.
  • DrawCircle: DrawCircle Draws a circle on image.
  • DrawCircle1: DrawCircle1 as DrawCircle, but just take a single double for ink.
  • DrawFlood: DrawFlood flood-fill image with ink, starting at position x , y.
  • DrawFlood1: DrawFlood1 as DrawFlood, but just take a single double for ink.
  • DrawSmudge: DrawSmudge smudge a section of image.

foreign_save

freqfilt

  • FwFFT: FwFFT transform an image to Fourier space.
  • InvFFT: InvFFT transform an image from Fourier space to real space.
  • FreqMult: FreqMult transformed to Fourier space, multipled with mask.
  • Spectrum: Spectrum make a displayable (ie. 8-bit unsigned int) power spectrum.
  • Phasecor: Phasecor convert the two input images to Fourier space, calculate phase-correlation, back to real space.

header

mosaicing

  • Merge: Merge joins two images left-right (with ref on the left) or up-down (with ref above) with a smooth seam.
  • Mosaic: Mosaic joins two images left-right (with ref on the left) or top-bottom (with ref above) given an approximate overlap.
  • Mosaic1: Mosaic1 This operation joins two images top-bottom (with sec on the right) or left-right (with sec at the bottom) given an approximate pair of tie-points.
  • Match: Match scale, rotate and translate sec so that the tie-points line up.
  • GlobalBalance: GlobalBalance can be used to remove contrast differences in an assembled mosaic.
  • ReMosaic: ReMosaic takes apart the mosaiced image in and rebuilds it, substituting images.

resample

  • Resize: Resize image
  • Rotate: Rotate image
  • Thumbnail: Thumbnail Make a thumbnail from a file
  • ThumbnailBuffer: ThumbnailBuffer Make a thumbnail from []byte
  • ThumbnailImage: ThumbnailImage Make a thumbnail from *Image

vip

  • DefaultInit: DefaultInit init vips by default
  • Init: Init starts up libvips
  • Shutdown: Shutdown drop caches and close plugins. Run with "--vips-leak" to do a leak check too.
  • LeakSet: LeakSet turn on or off vips leak checking
  • VersionString: VersionString get the VIPS version as a static string, including a build date and time.
  • Version: Version get the major, minor or micro library version, with flag values 0, 1 and 2.
  • Error: Error Get a pointer to the start of the error buffer as a C string.

vipsimage

  • New: New empty VipsImage
  • NewMemory: NewMemory creates a new VipsImage.
  • NewFromFile: NewFromFile opens filename for reading.
  • NewFromBuffer: NewFromBuffer loads an image from the formatted area of memory buf.
  • Height: Height return image height
  • Width: Width return image width
  • ProgressSet: ProgressSet ff set, vips will print messages about the progress of computation to stdout.
  • ImageSetProgress: ImageSetProgress vips signals evaluation progress via the “preeval”

Contributing

We appreciate your help!

vips's People

Contributors

gladmo avatar

Stargazers

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

Watchers

 avatar  avatar

Forkers

shiqiyue

vips's Issues

memory leak

test code


func init() {
	vips.DefaultInit()
	vips.LeakSet(true)
}

func main() {
	defer vips.Shutdown()
	const file = "./6584893551151716.jpg"
	buf, err := ioutil.ReadFile(file)
	if err != nil {
		log.Fatal(err)
	}

	img, err := vips.JPEGLoadBuffer(buf)
	if err != nil {
		log.Fatal(err)
	}
	defer img.Free()

	err = img.Crop(10, 10, 300, 200)
	if err != nil {
		log.Fatal(err)
	}

	buf1, _, err := img.JPEGSaveBuffer()
	if err != nil {
		log.Fatal(err)
	}
	img1, err := vips.JPEGLoadBuffer(buf1)
	if err != nil {
		log.Fatal(err)
	}
	defer img1.Free()
	img1.Save2file("./result1.jpg")
}

result is

2 objects alive:
0) VipsImage (0x16c1010), count=1
VipsImage (image), image class, 1x1 uchar, 1 band, multiband
1) VipsImage (0x16c1330), count=1
VipsImage (image), image class, 1x1 uchar, 1 band, multiband
memory: high-water mark 9.34 MB

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.