本文整理汇总了Golang中github.com/disintegration/imaging.Crop函数的典型用法代码示例。如果您正苦于以下问题:Golang Crop函数的具体用法?Golang Crop怎么用?Golang Crop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Crop函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetCube
// Sets skin.Processed to an isometric render of the head from a top-left angle (showing 3 sides).
func (skin *mcSkin) GetCube(width int) error {
// Crop out the top of the head
topFlat := imaging.Crop(skin.Image, image.Rect(8, 0, 16, 8))
// Resize appropriately, so that it fills the `width` when rotated 45 def.
topFlat = imaging.Resize(topFlat, int(float64(width)*math.Sqrt(2)/3+1), 0, imaging.NearestNeighbor)
// Create the Gift filter
filter := gift.New(
gift.Rotate(45, color.Transparent, gift.LinearInterpolation),
)
bounds := filter.Bounds(topFlat.Bounds())
top := image.NewNRGBA(bounds)
// Draw it on the filter, then smush it!
filter.Draw(top, topFlat)
top = imaging.Resize(top, width+2, width/3, imaging.NearestNeighbor)
// Skew the front and sides at 15 degree angles to match up with the
// head that has been smushed
front := skin.cropHead(skin.Image).(*image.NRGBA)
side := imaging.Crop(skin.Image, image.Rect(0, 8, 8, 16))
front = imaging.Resize(front, width/2, int(float64(width)/1.75), imaging.NearestNeighbor)
side = imaging.Resize(side, width/2, int(float64(width)/1.75), imaging.NearestNeighbor)
front = skewVertical(front, math.Pi/12)
side = skewVertical(imaging.FlipH(side), math.Pi/-12)
// Create a new image to assemble upon
skin.Processed = image.NewNRGBA(image.Rect(0, 0, width, width))
// Draw each side
draw.Draw(skin.Processed.(draw.Image), image.Rect(0, width/6, width/2, width), side, image.Pt(0, 0), draw.Src)
draw.Draw(skin.Processed.(draw.Image), image.Rect(width/2, width/6, width, width), front, image.Pt(0, 0), draw.Src)
// Draw the top we created
draw.Draw(skin.Processed.(draw.Image), image.Rect(-1, 0, width+1, width/3), top, image.Pt(0, 0), draw.Over)
return nil
}
开发者ID:spideynn,项目名称:imgd,代码行数:34,代码来源:process.go
示例2: ProcessImage
func (ipo *ImageProcessorOptions) ProcessImage(source *Image) (*Image, error) {
dest := &Image{format: source.format}
var wip image.Image
if ipo.ScaleX == -1 {
wip = imaging.FlipH(source.image)
} else {
wip = source.image
}
if ipo.X != 0 || ipo.Y != 0 || ipo.Width != source.Width() || ipo.Height != source.Height() {
r := image.Rectangle{image.Point{int(ipo.X), int(ipo.Y)}, image.Point{int(ipo.X + ipo.Width), int(ipo.Y + ipo.Height)}}
wip = imaging.Crop(wip, r)
}
var err error
switch dest.format {
case JPEG:
err = jpeg.Encode(&dest.buffer, wip, &jpeg.Options{int(ipo.Quality)})
case PNG:
err = png.Encode(&dest.buffer, wip)
default:
return nil, errors.New("attempt to encode to unsupported image format")
}
return dest, err
}
开发者ID:bookerzzz,项目名称:nibbleshell,代码行数:28,代码来源:processing.go
示例3: renderLowerBody
// Returns the legs.
func (skin *mcSkin) renderLowerBody() *image.NRGBA {
// This will be the base.
lowerBodyImg := image.NewNRGBA(image.Rect(0, 0, LlWidth+RlWidth, LlHeight))
rlImg := imaging.Crop(skin.Image, image.Rect(RlX, RlY, RlX+RlWidth, RlY+RlHeight))
// If it's an old skin, they don't have a Left Leg, so we'll just flip their right.
var llImg image.Image
if skin.is18Skin() {
llImg = imaging.Crop(skin.Image, image.Rect(LlX, LlY, LlX+LlWidth, LlY+LlHeight))
} else {
llImg = imaging.FlipH(rlImg)
}
return skin.drawLower(lowerBodyImg, rlImg, llImg.(*image.NRGBA))
}
开发者ID:spideynn,项目名称:imgd,代码行数:17,代码来源:process.go
示例4: Extract
func Extract(img image.Image, name string, X, Y, W, H float32, rotated bool) error {
dst := imaging.Crop(img, image.Rect(int(X), int(Y), int(X+W), int(Y+H)))
if rotated {
log.Fatal("图片被旋转过")
}
return imgutil.SaveImg(name, dst)
}
开发者ID:hyqhyq3,项目名称:extract,代码行数:7,代码来源:main.go
示例5: ResizeHandler
func ResizeHandler(w http.ResponseWriter, r *http.Request) {
// parse url vars
v := mux.Vars(r)
width, _ := v["width"]
height, _ := v["height"]
x, _ := strconv.Atoi(width)
y, _ := strconv.Atoi(height)
imageUrl, _ := v["imageUrl"]
m := getImg(imageUrl)
cropBox, _ := getFillCrop(m, float32(x)/float32(y))
cropRect := image.Rect(cropBox.X, cropBox.Y, cropBox.X+cropBox.Width, cropBox.Y+cropBox.Height)
croppedImg := imaging.Crop(m, cropRect)
// convert to opencv image
//srcImage := opencv.FromImage(m)
//if srcImage == nil {
// fmt.Printf("Couldn't create opencv Image")
//}
//defer srcImage.Release()
//croppedImage := opencv.Crop(srcImage, cropBox.X, cropBox.Y, cropBox.Width, cropBox.Height)
//resizedImage := opencv.Resize(croppedImage, x, y, opencv.CV_INTER_LINEAR)
resizedImage := imaging.Resize(croppedImg, x, y, imaging.CatmullRom)
jpeg.Encode(w, resizedImage, &jpeg.Options{Quality: 90})
}
开发者ID:zmilan,项目名称:go-resize,代码行数:26,代码来源:server.go
示例6: cropHelm
// Returns the head of the skin image overlayed with the helm.
func (skin *mcSkin) cropHelm(img image.Image) image.Image {
headImg := skin.cropHead(img)
helmImg := imaging.Crop(img, image.Rect(HelmX, HelmY, HelmX+HeadWidth, HelmY+HeadHeight))
skin.removeAlpha(helmImg)
fastDraw(headImg.(*image.NRGBA), helmImg, 0, 0)
return headImg
}
开发者ID:spideynn,项目名称:imgd,代码行数:9,代码来源:process.go
示例7: renderLowerArmor
// Returns the legs but with any armor which the user has.
func (skin *mcSkin) renderLowerArmor() *image.NRGBA {
// This will be the base.
lowerArmorBodyImg := skin.renderLowerBody()
// If it's an old skin, they don't have armor here.
if skin.is18Skin() {
// Get the armor layers from the skin and remove the Alpha.
ll2Img := imaging.Crop(skin.Image, image.Rect(Ll2X, Ll2Y, Ll2X+LlWidth, Ll2Y+LlHeight))
skin.removeAlpha(ll2Img)
rl2Img := imaging.Crop(skin.Image, image.Rect(Rl2X, Rl2Y, Rl2X+RlWidth, Rl2Y+RlHeight))
skin.removeAlpha(rl2Img)
return skin.drawLower(lowerArmorBodyImg, ll2Img, rl2Img)
}
return lowerArmorBodyImg
}
开发者ID:spideynn,项目名称:imgd,代码行数:18,代码来源:process.go
示例8: renderUpperBody
// Returns the torso and arms.
func (skin *mcSkin) renderUpperBody() *image.NRGBA {
// This will be the base.
upperBodyImg := image.NewNRGBA(image.Rect(0, 0, LaWidth+TorsoWidth+RaWidth, TorsoHeight))
torsoImg := imaging.Crop(skin.Image, image.Rect(TorsoX, TorsoY, TorsoX+TorsoWidth, TorsoY+TorsoHeight))
raImg := imaging.Crop(skin.Image, image.Rect(RaX, RaY, RaX+RaWidth, RaY+TorsoHeight))
// If it's an old skin, they don't have a Left Arm, so we'll just flip their right.
var laImg image.Image
if skin.is18Skin() {
laImg = imaging.Crop(skin.Image, image.Rect(LaX, LaY, LaX+LaWidth, LaY+TorsoHeight))
} else {
laImg = imaging.FlipH(raImg)
}
return skin.drawUpper(upperBodyImg, torsoImg, raImg, laImg.(*image.NRGBA))
}
开发者ID:spideynn,项目名称:imgd,代码行数:18,代码来源:process.go
示例9: resizeThumbnail
func resizeThumbnail(from *bytes.Buffer, spec *ThumbnailSpec) (to io.Reader, w int, h int, err error) {
src, name, err := image.Decode(from)
if err != nil {
return
}
srcB := src.Bounds()
var dst image.Image
if spec.CropToSquare && srcB.Dx() != srcB.Dy() {
var rect image.Rectangle
if srcB.Dx() > srcB.Dy() {
x1 := (srcB.Dx() - srcB.Dy()) / 2
x2 := srcB.Dx() - x1
rect = image.Rect(x1, 0, x2, srcB.Dy())
} else {
rect = image.Rect(0, 0, srcB.Dx(), srcB.Dx())
}
w = spec.Height
if (spec.Height > spec.Width && spec.Width != 0) || spec.Height == 0 {
w = spec.Width
}
h = w
cropedImg := imaging.Crop(src, rect)
rect = cropedImg.Bounds()
dst = resize.Resize(cropedImg, rect, w, h)
} else {
w, h = spec.CalculateRect(srcB, spec.CropToSquare)
if w >= srcB.Dx() || h >= srcB.Dy() {
w, h = srcB.Dx(), srcB.Dy()
}
rect := image.Rect(0, 0, srcB.Dx(), srcB.Dy())
dst = resize.Resize(src, rect, w, h)
}
var buf bytes.Buffer
switch name {
case "jpeg":
jpeg.Encode(&buf, dst, &jpeg.Options{95})
case "png":
png.Encode(&buf, dst)
case "gif":
jpeg.Encode(&buf, dst, &jpeg.Options{95})
case "bmp":
jpeg.Encode(&buf, dst, &jpeg.Options{95})
}
to = &buf
return
}
开发者ID:jmptrader,项目名称:tenpu,代码行数:55,代码来源:handlers.go
示例10: renderUpperArmor
// Returns the torso and arms but with any armor which the user has.
func (skin *mcSkin) renderUpperArmor() *image.NRGBA {
// This will be the base.
upperArmorBodyImg := skin.renderUpperBody()
// If it's an old skin, they don't have armor here.
if skin.is18Skin() {
// Get the armor layers from the skin and remove the Alpha.
torso2Img := imaging.Crop(skin.Image, image.Rect(Torso2X, Torso2Y, Torso2X+TorsoWidth, Torso2Y+TorsoHeight))
skin.removeAlpha(torso2Img)
la2Img := imaging.Crop(skin.Image, image.Rect(La2X, La2Y, La2X+LaWidth, La2Y+TorsoHeight))
skin.removeAlpha(la2Img)
ra2Img := imaging.Crop(skin.Image, image.Rect(Ra2X, Ra2Y, Ra2X+RaWidth, Ra2Y+TorsoHeight))
skin.removeAlpha(ra2Img)
return skin.drawUpper(upperArmorBodyImg, torso2Img, ra2Img, la2Img)
}
return upperArmorBodyImg
}
开发者ID:spideynn,项目名称:imgd,代码行数:21,代码来源:process.go
示例11: Handle
func (imageHandler) Handle(media MediaLibrary, file multipart.File, option *Option) error {
if err := media.Store(media.URL("original"), option, file); err == nil {
file.Seek(0, 0)
if img, err := imaging.Decode(file); err == nil {
if format, err := getImageFormat(media.URL()); err == nil {
if cropOption := media.GetCropOption("original"); cropOption != nil {
img = imaging.Crop(img, *cropOption)
}
// Save default image
var buffer bytes.Buffer
imaging.Encode(&buffer, img, *format)
media.Store(media.URL(), option, &buffer)
for key, size := range media.GetSizes() {
newImage := img
if cropOption := media.GetCropOption(key); cropOption != nil {
newImage = imaging.Crop(newImage, *cropOption)
}
dst := imaging.Thumbnail(newImage, size.Width, size.Height, imaging.Lanczos)
var buffer bytes.Buffer
imaging.Encode(&buffer, dst, *format)
media.Store(media.URL(key), option, &buffer)
}
return nil
} else {
return err
}
} else {
return err
}
} else {
return err
}
}
开发者ID:8legd,项目名称:qor-media_library,代码行数:37,代码来源:handlers.go
示例12: Create
func Create(c *gin.Context) {
file, fileHeader, err := c.Request.FormFile("file")
if err != nil {
c.Error(err)
return
}
_, h := parseVal("h", c)
_, w := parseVal("w", c)
_, x := parseVal("x", c)
_, y := parseVal("y", c)
img, _, err := image.Decode(file)
if err != nil {
c.Error(err)
return
}
log.Debug("Crop w:%v h:%v x:%v y:%v", w, h, x, y)
rect := convertToRectangle(int(w), int(h), int(x), int(y))
log.Debug("Rect", rect)
croppedImg := imaging.Crop(img, rect)
db := utils.GetDb(c)
gridFile, err := db.GridFS("fs").Create(fileHeader.Filename)
if err != nil {
c.Error(err)
return
}
buffer := new(bytes.Buffer)
jpeg.Encode(buffer, croppedImg, nil)
gridFile.SetName(fileHeader.Filename)
gridFile.SetContentType(fileHeader.Header.Get("Content-Type"))
_, err = io.Copy(gridFile, buffer)
if err != nil {
c.Error(err)
return
}
file.Close()
gridFile.Close()
c.JSON(http.StatusOK, gin.H{"_id": gridFile.Id()})
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:49,代码来源:images.go
示例13: fitCropScale
func fitCropScale(i image.Image, r image.Rectangle) image.Image {
wantRatio := float64(r.Bounds().Dx()) / float64(r.Bounds().Dy())
haveRatio := float64(i.Bounds().Dx()) / float64(i.Bounds().Dy())
sliceRect := image.Rectangle{}
if haveRatio > wantRatio {
wantwidth := wantRatio * float64(i.Bounds().Dy())
sliceRect = image.Rect(i.Bounds().Dx()/2-int(wantwidth/2), 0, i.Bounds().Dx()/2+int(wantwidth/2), i.Bounds().Dy())
} else {
wantheight := float64(i.Bounds().Dx()) / wantRatio
sliceRect = image.Rect(0, i.Bounds().Dy()/2-int(wantheight/2), i.Bounds().Dx(), i.Bounds().Dy()/2+int(wantheight/2))
}
return imaging.Resize(imaging.Crop(i, sliceRect), r.Dx(), r.Dy(), imaging.Lanczos)
}
开发者ID:srinathh,项目名称:mobilehtml5app,代码行数:16,代码来源:static.go
示例14: cut
func (i *ImgNet) cut(p image.Point, img *image.Image) []float64 {
rect := image.Rect(p.X, p.Y, p.X+i.w, p.Y+i.h)
croppedImg := imaging.Crop(*img, rect)
rgb := make([]float64, i.w*i.h*3)
for y := 0; y < croppedImg.Bounds().Dy(); y++ {
for x := 0; x < croppedImg.Bounds().Dx(); x++ {
r, g, b, _ := croppedImg.At(x, y).RGBA()
index := x + y*i.w*3
rgb[index] = float64(r) / 65535
rgb[index+1] = float64(g) / 65535
rgb[index+2] = float64(b) / 65535
}
}
return rgb
}
开发者ID:avesanen,项目名称:neuro,代码行数:17,代码来源:main.go
示例15: NewCubemap
func NewCubemap(name string, baseImage image.Image, lod bool) *CubeMap {
cubeMap := new(CubeMap)
x := baseImage.Bounds().Max.X
y := baseImage.Bounds().Max.Y
cubeMap.Name = name
cubeMap.Lod = lod
cubeMap.Right = imaging.Crop(baseImage, image.Rect(x/2, y/3, 3*x/4, 2*y/3))
cubeMap.Left = imaging.Crop(baseImage, image.Rect(0, y/3, x/4, 2*y/3))
cubeMap.Top = imaging.Crop(baseImage, image.Rect(x/4, 0, x/2, y/3))
cubeMap.Bottom = imaging.Crop(baseImage, image.Rect(x/4, 2*y/3, x/2, y))
cubeMap.Back = imaging.Crop(baseImage, image.Rect(3*x/4, y/3, x, 2*y/3))
cubeMap.Front = imaging.Crop(baseImage, image.Rect(x/4, y/3, x/2, 2*y/3))
return cubeMap
}
开发者ID:walesey,项目名称:go-engine,代码行数:17,代码来源:Cubemap.go
示例16: MakeImages
func MakeImages(rect *image.Rectangle, file io.Reader) ([]*bytes.Buffer, error) {
runtime.GOMAXPROCS(runtime.NumCPU())
ar := aspectRatio(rect)
if ar < RATIO {
return nil, fmt.Errorf("makeImages: aspect ratio is too small")
} else if ar > RATIO {
cropRatio(rect)
}
img, _, err := image.Decode(file)
if err != nil {
return nil, err
}
img = imaging.Clone(img)
top := rect.Min.Y
square := squareHeight(rect)
space := spaceHeight(rect)
buffers := make([]*bytes.Buffer, 5, 5)
for i := 0; i < 5; i++ {
new_rect := image.Rect(rect.Min.X, top, rect.Max.X, top+square)
new_img := imaging.Crop(img, new_rect)
buffers[i] = bytes.NewBuffer(make([]byte, 0))
err = png.Encode(buffers[i], new_img)
if err != nil {
panic(err)
}
top = top + square + space
}
return buffers, nil
}
开发者ID:noahgoldman,项目名称:dotaprofiles,代码行数:38,代码来源:transform.go
示例17: Process
// Process begins the process of loading the source image, partitioning it, and
// determining all of the unique images. Once complete, it produces a report
// which is written to a file called report.html in the current directory.
func (p *ImageSet) Process() {
sourceImage := p.getSourceImage()
if sourceImage == nil {
return
}
bounds := sourceImage.Bounds()
numX, numY := calculateNumberImages(bounds)
p.stride = numX
p.images = make([]uint64, numX*numY)
p.orientations = make([]byte, numX*numY)
for y := 0; y < numY; y++ {
for x := 0; x < numX; x++ {
bounds := image.Rect(x*128, y*128, (x+1)*128, (y+1)*128)
p.AddImage(imaging.Crop(sourceImage, bounds), x, y)
}
}
p.WriteImageFiles()
p.WriteReport(bounds)
}
开发者ID:marcboudreau,项目名称:sc4texture,代码行数:26,代码来源:imageset.go
示例18: Do
// Do performs the resize
func Do(r io.Reader, w io.Writer, crop *image.Rectangle, width, height int) error {
// read it
img, err := imaging.Decode(r)
if err != nil {
return err
}
// if crop isn't nil
if crop != nil {
// then crop it
img = imaging.Crop(img, *crop)
}
// resize it
img = imaging.Resize(img, width, height, imaging.MitchellNetravali)
// write it
if err := imaging.Encode(w, img, imaging.PNG); err != nil {
return err
}
return nil
}
开发者ID:TeamTrumpet,项目名称:waltz,代码行数:24,代码来源:waltz.go
示例19: SaveAndCropImage
func SaveAndCropImage(isCreate bool) func(scope *gorm.Scope) {
return func(scope *gorm.Scope) {
for _, field := range scope.Fields() {
if media, ok := field.Field.Addr().Interface().(MediaLibrary); ok {
option := parseTagOption(field.Tag.Get("media_library"))
if media.GetFileHeader() != nil || media.NeedCrop() {
var file multipart.File
var err error
if fileHeader := media.GetFileHeader(); fileHeader != nil {
file, err = media.GetFileHeader().Open()
} else {
file, err = media.Retrieve(media.URL("original"))
}
if scope.Err(err) != nil {
return
}
if url := media.GetURL(option, scope, field, media); url == "" {
scope.Err(errors.New("invalid URL"))
} else {
result, _ := json.Marshal(map[string]string{"Url": url})
media.Scan(string(result))
}
if isCreate && !scope.HasError() {
if value, err := media.Value(); err == nil {
gorm.Update(scope.New(scope.Value).InstanceSet("gorm:update_attrs", map[string]interface{}{field.DBName: value}))
}
}
if file != nil {
defer file.Close()
if media.IsImage() {
// Save Original Image
if scope.Err(media.Store(media.URL("original"), option, file)) == nil {
file.Seek(0, 0)
// Crop & Resize
if img, err := imaging.Decode(file); scope.Err(err) == nil {
if format, err := getImageFormat(media.URL()); scope.Err(err) == nil {
if cropOption := media.GetCropOption("original"); cropOption != nil {
img = imaging.Crop(img, *cropOption)
}
// Save default image
var buffer bytes.Buffer
imaging.Encode(&buffer, img, *format)
media.Store(media.URL(), option, &buffer)
for key, size := range media.GetSizes() {
newImage := img
if cropOption := media.GetCropOption(key); cropOption != nil {
newImage = imaging.Crop(newImage, *cropOption)
}
dst := imaging.Thumbnail(newImage, size.Width, size.Height, imaging.Lanczos)
var buffer bytes.Buffer
imaging.Encode(&buffer, dst, *format)
media.Store(media.URL(key), option, &buffer)
}
}
}
}
} else {
// Save File
scope.Err(media.Store(media.URL(), option, file))
}
}
}
}
}
}
}
开发者ID:nilslice,项目名称:qor,代码行数:75,代码来源:callback.go
示例20: cropHead
// Returns the head of the skin image.
func (skin *mcSkin) cropHead(img image.Image) image.Image {
return imaging.Crop(img, image.Rect(HeadX, HeadY, HeadX+HeadWidth, HeadY+HeadHeight))
}
开发者ID:spideynn,项目名称:imgd,代码行数:4,代码来源:process.go
注:本文中的github.com/disintegration/imaging.Crop函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论