crop

package
v0.0.0-...-a42f776 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2015 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Crop package exporting the Crop() function used to crop images

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Crop

func Crop(imageData []byte, cWidth int, cHeight int, w io.Writer)

Crop() takes in four parameters:

imageData : byte[] representing the input image

cWidth : An int specifying the desired width of the cropped image

cHeight : An int specifying the desired height of the cropped image

w : An io.Writer to which to write the encoded ropped image bytes to

Example
package main

import (
	"bufio"
	"fmt"
	"github.com/amitsaha/cropit/crop"
	"io/ioutil"
	"log"
	"os"
	"path/filepath"
)

func main() {
	// Test image to crop
	inputFilePath := "../test_images/cat1.jpg"
	imageData, err := ioutil.ReadFile(inputFilePath)
	if err != nil {
		log.Fatal("Cannot open file", err)
	}

	// Write the cropped image to a file cropped_cat1.jpg
	croppedFileDir, fileName := filepath.Split(inputFilePath)
	croppedFileName := fmt.Sprintf("%scropped_%s", croppedFileDir, fileName)
	croppedFile, err := os.Create(croppedFileName)
	if err != nil {
		log.Fatal("Could not create file for cropped image")
	}
	defer croppedFile.Close()

	croppedFileWriter := bufio.NewWriter(croppedFile)
	// Crop width and height
	cWidth := 5000
	cHeight := 4000
	crop.Crop(imageData, cWidth, cHeight, croppedFileWriter)
	croppedFileWriter.Flush()
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL