Simple two-golang image processing library: Picture clipping

Source: Internet
Author: User
Tags image processing library
This is a creation in Article, where the information may have evolved or changed.

Simple two-golang image processing library: Picture clipping

Function

Official image processing library in 1.Go language

2. Scale the JPG and PNG images in a simple package | Crop Library

Instructions for use

1. First download

go get -v -u github.com/hunterhug/go-image

2. Main functions

Proportional scaling by width, the first parameter is an image file, the second parameter is the scaled save file path

err := ScaleF2F(filename, savepath, width)

Proportional scaling by width and height, the first parameter is an image file, the second parameter is the scaled save file path

err = ThumbnailF2F(filename, save1path, width, height)

Detects the real file type of the image file and returns the real filename, the image file location

realfilename, err := RealImageName(savepath)

Change the image file name, the first parameter is the original name of the file, the second parameter is the name of the file after renaming, the third parameter indicates whether to rename

err=ChangeImageName(savepath,realfilename,false)

Using the example

Example.go

Package Mainimport ("FMT". "Github.com/hunterhug/go-image/go_image")//A picture file is scaled and stored in another file, func main () {//Prints the current folder location FMT. Printf ("This file folder location:%s\n", CurDir ())//image location FileName: = "./testdata/gopher.png"//save location Savepath: = "./testdata/go    Pher400.jpg "Save1path: ="./testdata/gopher400*400.png "//width, height width: = Height: = 400//proportional scaling by width ERR: = scalef2f (filename, savepath, width) if err! = Nil {fmt. Printf ("%s\n", err. Error ())}else{FMT. Printf (Generate scale by width graph%s\n, Savepath)}//proportional scaling by width and height err = thumbnailf2f (filename, save1path, width, height) if E RR! = nil {fmt. Printf ("%s\n", err. Error ())}else{FMT.    Printf ("Generate by width height scale graph%s\n", save1path)}//View the real name of the image file//such as./testdata/gopher400.jpg is actually a PNG type, but the name is wrong and needs correcting! Realfilename, err: = Realimagename (Savepath) if err! = Nil {fmt. Printf ("%s\n", err. Error ())} else {fmt. Printf ("Real file name:%s\n", Realfilename)}//file renamed, not mandatory err=chAngeimagename (savepath,realfilename,false) if err!=nil{fmt. Printf ("File rename failed:%s%s", Realfilename,err. Error ())}//file renamed, Mandatory err=changeimagename (Savepath,realfilename,true) if err!=nil{fmt. Printf ("File rename failed:%s%s", Realfilename,err. Error ())}else{FMT. Println ("successfully renamed")}}

Results

本文件文件夹位置:/home/hunterhug/golang/pikapika/src/github.com/hunterhug/go-image生成按宽度缩放图./testdata/gopher400.jpg生成按宽度高度缩放图./testdata/gopher400*400.png真正的文件名:./testdata/gopher400.png文件改名失败:./testdata/gopher400.png文件已经存在

Original picture

Width 200px equal scale cropping

Width 200px, height 400px scale cropping

From

This was a Graphics library for the Go programming language.

Unless otherwise noted, the Graphics-go source files are distributed
Under the Bsd-style license found in the license file.

Contributions should follow the same procedure as for the Go project:
Http://golang.org/doc/contribute.html

Contact

Time:2016/8/10

Author:hunterhug

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.