package image type Basic struct { Cache Path string File string Background string ViewPoint *Point ViewSize *Size Angle float64 } // SetAngle 设置旋转角度 func (i *Basic) SetAngle(angle float64) { i.Angle = angle } // SetSize 设置目标尺寸 func (i *Basic) SetSize(width, height uint) { i.ViewSize = NewSize(width, height) } // SetPoint 设置图片的x、y 坐标 func (i *Basic) SetPoint(x, y float64) { i.ViewPoint = NewPoint(x, y) } // SetFile 设置处理的图片 func (i *Basic) SetFile(file string) { i.File = file } // SetBackground 设置背景色 func (i *Basic) SetBackground(background string) { i.Background = background } // Position 计算裁切的x、y及宽高 func (i *Basic) Position(position string, width, height uint, size *Size) (dx, dy int, dWidth, dHeight uint) { x := 0 y := 0 scale := 1.0 if width < size.Width { scale = CustomScale(width, size.Width) width = size.Width } if height < size.Height { scale = CustomScale(height, size.Height) height = size.Height } paddingLeft := width - size.Width paddingTop := height - size.Height if position == "right" { x = int(paddingLeft) } if position == "center" { x = int(paddingLeft / 2) y = int(paddingTop / 2) } if position == "right|center" { x = int(paddingLeft) y = int(paddingTop / 2) } if position == "left|center" { y = int(paddingTop / 2) } return x, y, uint(float64(size.Width) * scale), uint(float64(size.Height) * scale) }