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 ¶
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.
Click to show internal directories.
Click to hide internal directories.