Beispiel #1
0
Datei: crop.go Projekt: hawx/img
func runCrop(cmd *hadfield.Command, args []string) {
	i, data := utils.ReadStdin()

	direction := utils.Centre

	if cropTop {
		direction = utils.Top
	} else if cropTopRight {
		direction = utils.TopRight
	} else if cropRight {
		direction = utils.Right
	} else if cropBottomRight {
		direction = utils.BottomRight
	} else if cropBottom {
		direction = utils.Bottom
	} else if cropBottomLeft {
		direction = utils.BottomLeft
	} else if cropLeft {
		direction = utils.Left
	} else if cropTopLeft {
		direction = utils.TopLeft
	}

	if cropCircle {
		i = crop.Circle(i, cropSize, direction)
	} else if cropTriangle {
		i = crop.Triangle(i, cropSize, direction)
	} else {
		i = crop.Square(i, cropSize, direction)
	}

	utils.WriteStdout(i, data)
}
Beispiel #2
0
func runGreyscale(cmd *hadfield.Command, args []string) {
	i, data := utils.ReadStdin()

	if greyscaleAverage {
		i = greyscale.Average(i)
	} else if greyscaleLightness {
		i = greyscale.Lightness(i)
	} else if greyscaleLuminosity {
		i = greyscale.Luminosity(i)
	} else if greyscaleMaximal {
		i = greyscale.Maximal(i)
	} else if greyscaleMinimal {
		i = greyscale.Minimal(i)
	} else if greyscaleRed {
		i = greyscale.Red(i)
	} else if greyscaleGreen {
		i = greyscale.Green(i)
	} else if greyscaleBlue {
		i = greyscale.Blue(i)
	} else {
		i = greyscale.Greyscale(i)
	}

	utils.WriteStdout(i, data)
}
Beispiel #3
0
func main() {
	var (
		long  = flag.Bool("long", false, "")
		short = flag.Bool("short", false, "")
		usage = flag.Bool("usage", false, "")
	)

	os.Args = utils.GetOutput(os.Args)
	flag.Parse()

	if *long {
		fmt.Println(
			"  Applies a simple lomo effect to the image, boosting its saturation and\n" +
				"  composing with a black edged mask.",
		)

	} else if *short {
		fmt.Println("applies a simple lomo effect to the image")

	} else if *usage {
		fmt.Println("lomo [options]")

	} else {
		img, data := utils.ReadStdin()

		// http://the.taoofmac.com/space/blog/2005/08/23/2359
		img = contrast.Adjust(img, 1.2)
		img = channel.Adjust(img, utils.Multiplier(1.2), channel.Saturation)
		img = blend.Multiply(img, maskFor(img))

		utils.WriteStdout(img, data)
	}
}
Beispiel #4
0
Datei: blur.go Projekt: hawx/img
func runBlur(cmd *hadfield.Command, args []string) {
	var style blur.Style

	switch blurStyle {
	case "clamp":
		style = blur.CLAMP
	case "ignore":
		style = blur.IGNORE
	case "wrap":
		style = blur.WRAP
	default:
		utils.Warn("--style must be one of 'clamp', 'ignore' or 'wrap'")
		os.Exit(2)
	}

	i, data := utils.ReadStdin()

	if blurBox {
		i = blur.Box(i, blurRadius, style)
	} else {
		i = blur.Gaussian(i, blurRadius, blurGaussian, style)
	}

	utils.WriteStdout(i, data)
}
Beispiel #5
0
Datei: hxl.go Projekt: hawx/img
func runHxl(cmd *hadfield.Command, args []string) {
	i, data := utils.ReadStdin()

	if hxlCols > 0 {
		hxlWidth = utils.SizeForCols(i, hxlCols).W
	}

	i = pixelate.Hxl(i, hxlWidth)
	utils.WriteStdout(i, data)
}
Beispiel #6
0
Datei: vxl.go Projekt: hawx/img
func runVxl(cmd *hadfield.Command, args []string) {
	i, data := utils.ReadStdin()

	if vxlRows > 0 {
		vxlHeight = utils.SizeForRows(i, vxlRows).H
	}

	i = pixelate.Vxl(i, vxlHeight, vxlFlip, vxlTop, vxlLeft, vxlRight)
	utils.WriteStdout(i, data)
}
Beispiel #7
0
func runSharpen(cmd *hadfield.Command, args []string) {
	i, data := utils.ReadStdin()

	if sharpenUnsharp {
		i = sharpen.UnsharpMask(i, sharpenRadius, sharpenSigma, sharpenAmount, sharpenThreshold)
	} else {
		i = sharpen.Sharpen(i, sharpenRadius, sharpenSigma)
	}

	utils.WriteStdout(i, data)
}
Beispiel #8
0
func runVibrance(cmd *hadfield.Command, args []string) {
	image, exif := utils.ReadStdin()

	if vibranceExp {
		image = vibrance.Exp(image, vibranceBy)
	} else {
		image = vibrance.Adjust(image, vibranceBy)
	}

	utils.WriteStdout(image, exif)
}
Beispiel #9
0
func run(scale float64, f Cropper) {
	img, data := utils.ReadStdin()

	b := img.Bounds()
	s := int(float64(min(b.Dx(), b.Dy())) * scale)

	inner := f(img, s, utils.Centre)

	img = blend.Normal(img, flip(inner))

	utils.WriteStdout(img, data)
}
Beispiel #10
0
func runContrast(cmd *hadfield.Command, args []string) {
	i, data := utils.ReadStdin()

	if contrastSigmoidal {
		i = contrast.Sigmoidal(i, contrastFactor, contrastMidpoint)
	} else if contrastLinear {
		i = contrast.Linear(i, contrastFactor)
	} else {
		i = contrast.Adjust(i, contrastFactor)
	}

	utils.WriteStdout(i, data)
}
Beispiel #11
0
func runChannel(cmd *hadfield.Command, args []string) {
	i, data := utils.ReadStdin()
	var adj utils.Adjuster

	if utils.FlagVisited("by", cmd.Flag) {
		adj = utils.Adder(channelBy)
	} else {
		adj = utils.Multiplier(channelRatio)
	}

	if !(channelRed || channelGreen || channelBlue || channelHue ||
		channelSaturation || channelLightness || channelBrightness || channelAlpha) {
		channelRed = true
		channelGreen = true
		channelBlue = true
	}

	if channelRed {
		i = channel.Adjust(i, adj, channel.Red)
	}
	if channelGreen {
		i = channel.Adjust(i, adj, channel.Green)
	}
	if channelBlue {
		i = channel.Adjust(i, adj, channel.Blue)
	}

	if channelHue {
		i = channel.Adjust(i, adj, channel.Hue)
	}
	if channelSaturation {
		i = channel.Adjust(i, adj, channel.Saturation)
	}
	if channelLightness {
		i = channel.Adjust(i, adj, channel.Lightness)
	}
	if channelBrightness {
		i = channel.Adjust(i, adj, channel.Brightness)
	}

	if channelAlpha {
		i = channel.Adjust(i, adj, channel.Alpha)
	}

	utils.WriteStdout(i, data)
}
Beispiel #12
0
func main() {
	flag.Parse()

	img, data := utils.ReadStdin()

	s := quantise.LEAST
	if *strategy == "MOST" {
		s = quantise.MOST
	}

	img = quantise.Quantise(img, quantise.OctreeQuantiser{
		Depth:    uint8(*depth),
		Size:     *size,
		Strategy: s,
	})

	utils.WriteStdout(img, data)
}
Beispiel #13
0
func runPixelate(cmd *hadfield.Command, args []string) {
	i, data := utils.ReadStdin()

	// Default
	style := pixelate.FITTED

	if pixelateCrop {
		style = pixelate.CROPPED
	}

	if pixelateRows > 0 && pixelateCols > 0 {
		pixelateSize = utils.SizeForRowsAndCols(i, pixelateRows, pixelateCols)
	} else if pixelateRows > 0 {
		pixelateSize = utils.SizeForRows(i, pixelateRows)
	} else if pixelateCols > 0 {
		pixelateSize = utils.SizeForCols(i, pixelateCols)
	}

	i = pixelate.Pixelate(i, pixelateSize, style)
	utils.WriteStdout(i, data)
}
Beispiel #14
0
func runLevels(cmd *hadfield.Command, args []string) {
	i, data := utils.ReadStdin()

	if !levelsRed && !levelsGreen && !levelsBlue {
		levelsRed = true
		levelsGreen = true
		levelsBlue = true
	}

	if levelsRed {
		i = runLevelsOnChannel(cmd, args, i, channel.Red)
	}

	if levelsGreen {
		i = runLevelsOnChannel(cmd, args, i, channel.Green)
	}

	if levelsBlue {
		i = runLevelsOnChannel(cmd, args, i, channel.Blue)
	}

	utils.WriteStdout(i, data)
}
Beispiel #15
0
Datei: blend.go Projekt: hawx/img
func runBlend(cmd *hadfield.Command, args []string) {
	if blendModes {
		printModes()
	}

	a, data := utils.ReadStdin()

	path := args[0]
	file, _ := os.Open(path)
	defer file.Close()
	b, _, _ := image.Decode(file)
	var f (func(a, b image.Image) image.Image)

	b = blend.Fade(b, blendOpacity)

	if blendFit {
		ab := a.Bounds()
		bb := b.Bounds()

		// Need to work this out better, see
		// http://www.codinghorror.com/blog/2007/07/better-image-resizing.html
		if bb.Dx() < ab.Dx() || bb.Dy() < ab.Dy() {
			// b is going to get BIGGER
			b = resize.Resize(uint(ab.Dx()), uint(ab.Dy()), b, resize.Bilinear)
		} else {
			// b is going to get SMALLER
			b = resize.Resize(uint(ab.Dx()), uint(ab.Dy()), b, resize.Bicubic)
		}
	}

	if blendNormal {
		f = blend.Normal
	} else if blendDissolve {
		f = blend.Dissolve

	} else if blendDarken {
		f = blend.Darken
	} else if blendMultiply {
		f = blend.Multiply
	} else if blendBurn {
		f = blend.Burn
	} else if blendLinearBurn {
		f = blend.LinearBurn
	} else if blendDarker {
		f = blend.Darker

	} else if blendLighten {
		f = blend.Lighten
	} else if blendScreen {
		f = blend.Screen
	} else if blendDodge {
		f = blend.Dodge
	} else if blendLinearDodge {
		f = blend.LinearDodge
	} else if blendLighter {
		f = blend.Lighter

	} else if blendOverlay {
		f = blend.Overlay
	} else if blendSoftLight {
		f = blend.SoftLight
	} else if blendHardLight {
		f = blend.HardLight
	} else if blendVividLight {
		f = blend.VividLight
	} else if blendLinearLight {
		f = blend.LinearLight
	} else if blendPinLight {
		f = blend.PinLight
	} else if blendHardMix {
		f = blend.HardMix

	} else if blendDifference {
		f = blend.Difference
	} else if blendExclusion {
		f = blend.Exclusion
	} else if blendAddition {
		f = blend.Addition
	} else if blendSubtraction {
		f = blend.Subtraction

	} else if blendHue {
		f = blend.Hue
	} else if blendSaturation {
		f = blend.Saturation
	} else if blendColor {
		f = blend.Color
	} else if blendLuminosity {
		f = blend.Luminosity

	} else {
		f = blend.Normal
	}

	utils.WriteStdout(f(a, b), data)
}