当前位置: 首页>>代码示例>>Golang>>正文


Golang MagickWand.CropImage方法代码示例

本文整理汇总了Golang中github.com/gographics/imagick/imagick.MagickWand.CropImage方法的典型用法代码示例。如果您正苦于以下问题:Golang MagickWand.CropImage方法的具体用法?Golang MagickWand.CropImage怎么用?Golang MagickWand.CropImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/gographics/imagick/imagick.MagickWand的用法示例。


在下文中一共展示了MagickWand.CropImage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: crop

func crop(mw *imagick.MagickWand, x, y int, cols, rows uint) error {
	var result error
	result = nil

	imCols := mw.GetImageWidth()
	imRows := mw.GetImageHeight()

	if x < 0 {
		x = 0
	}
	if y < 0 {
		y = 0
	}

	if uint(x) >= imCols || uint(y) >= imRows {
		result = fmt.Errorf("x, y more than image cols, rows")
		return result
	}

	if cols == 0 || imCols < uint(x)+cols {
		cols = imCols - uint(x)
	}

	if rows == 0 || imRows < uint(y)+rows {
		rows = imRows - uint(y)
	}

	fmt.Print(fmt.Sprintf("wi_crop(im, %d, %d, %d, %d)\n", x, y, cols, rows))

	result = mw.CropImage(cols, rows, x, y)

	return result
}
开发者ID:ShikangYang,项目名称:go-img,代码行数:33,代码来源:zscale.go

示例2: crop

func crop(mw *imagick.MagickWand, geo btcdn.GeoBox) (err error) {
	offsetX, offsetY, err := calculateGravityOffsets(int(mw.GetImageWidth()), int(mw.GetImageHeight()), geo)
	if err != nil {
		return
	}
	err = mw.CropImage(uint(geo.Width()), uint(geo.Height()), offsetX, offsetY)
	if err != nil {
		return
	}

	return
}
开发者ID:bootic,项目名称:btcdn,代码行数:12,代码来源:adapter.go

示例3: proportion

func proportion(mw *imagick.MagickWand, proportion int, cols uint, rows uint) error {
	var result error
	result = nil

	imCols := mw.GetImageWidth()
	imRows := mw.GetImageHeight()

	if proportion == 0 {
		fmt.Sprintf("p=0, wi_scale(im, %d, %d)\n", cols, rows)
		result = mw.ResizeImage(cols, rows, imagick.FILTER_UNDEFINED, 1.0)

	} else if proportion == 1 {

		if cols == 0 || rows == 0 {
			if cols > 0 {
				rows = uint(round(float64((cols / imCols) * imRows)))
			} else {
				cols = uint(round(float64((rows / imRows) * imCols)))
			}
			fmt.Sprintf("p=1, wi_scale(im, %d, %d)\n", cols, rows)
			result = mw.ResizeImage(cols, rows, imagick.FILTER_UNDEFINED, 1.0)
		} else {
			var x, y, sCols, sRows uint
			x, y = 0, 0

			colsRate := cols / imCols
			rowsRate := rows / imRows

			if colsRate > rowsRate {
				sCols = cols
				sRows = uint(round(float64(colsRate * imRows)))
				y = uint(math.Floor(float64((sRows - rows) / 2.0)))
			} else {
				sCols = uint(round(float64(rowsRate * imCols)))
				sRows = rows
				x = uint(math.Floor(float64((sCols - cols) / 2.0)))
			}

			fmt.Sprintf("p=2, wi_scale(im, %d, %d)\n", sCols, sRows)
			result = mw.ResizeImage(sCols, sRows, imagick.FILTER_UNDEFINED, 1.0)

			fmt.Sprintf("p=2, wi_crop(im, %d, %d, %d, %d)\n", x, y, cols, rows)
			result = mw.CropImage(cols, rows, int(x), int(y))
		}

	} else if proportion == 2 {
		x := int(math.Floor(float64((imCols - cols) / 2.0)))
		y := int(math.Floor(float64((imRows - rows) / 2.0)))
		fmt.Sprintf("p=3, wi_crop(im, %d, %d, %d, %d)\n", x, y, cols, rows)
		result = mw.CropImage(cols, rows, x, y)

	} else if proportion == 3 {
		if cols == 0 || rows == 0 {
			var rate uint
			if cols > 0 {
				rate = cols
			} else {
				rate = rows
			}
			rows = uint(round(float64(imRows * rate / 100)))
			cols = uint(round(float64(imCols * rate / 100)))
			fmt.Sprintf("p=3, wi_scale(im, %d, %d)\n", cols, rows)
			result = mw.ResizeImage(cols, rows, imagick.FILTER_UNDEFINED, 1.0)
		} else {
			rows = uint(round(float64(imRows * rows / 100)))
			cols = uint(round(float64(imCols * cols / 100)))
			fmt.Sprintf("p=3, wi_scale(im, %d, %d)\n", cols, rows)
			result = mw.ResizeImage(cols, rows, imagick.FILTER_UNDEFINED, 1.0)
		}

	} else if proportion == 4 {
		var rate float64
		rate = 1.0
		if cols == 0 || rows == 0 {
			if cols > 0 {
				rate = float64(cols / imCols)
			} else {
				rate = float64(rows / imRows)
			}
		} else {
			rateCol := cols / imCols
			rateRow := rows / imRows
			if rateCol < rateRow {
				rate = float64(rateCol)
			} else {
				rate = float64(rateRow)
			}
		}

		cols = uint(round(float64(float64(imCols) * rate)))
		rows = uint(round(float64(float64(imRows) * rate)))
		fmt.Sprintf("p=4, wi_scale(im, %d, %d)\n", cols, rows)
		result = mw.ResizeImage(cols, rows, imagick.FILTER_UNDEFINED, 1.0)
	}

	return result

}
开发者ID:ShikangYang,项目名称:go-img,代码行数:98,代码来源:zscale.go


注:本文中的github.com/gographics/imagick/imagick.MagickWand.CropImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。