當前位置: 首頁>>代碼示例>>Golang>>正文


Golang MagickWand.ResizeImage方法代碼示例

本文整理匯總了Golang中github.com/gographics/imagick/imagick.MagickWand.ResizeImage方法的典型用法代碼示例。如果您正苦於以下問題:Golang MagickWand.ResizeImage方法的具體用法?Golang MagickWand.ResizeImage怎麽用?Golang MagickWand.ResizeImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/gographics/imagick/imagick.MagickWand的用法示例。


在下文中一共展示了MagickWand.ResizeImage方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: resize

func (i *Image) resize(wand *imagick.MagickWand, w, h uint) {
	ow := wand.GetImageWidth()
	oh := wand.GetImageHeight()

	if (float64(ow) / float64(oh)) < (float64(w) / float64(h)) {
		h = oh * w / ow
	} else {
		w = ow * h / oh
	}

	wand.SetImageInterpolateMethod(imagick.INTERPOLATE_PIXEL_BICUBIC)
	wand.ResizeImage(w, h, imagick.FILTER_LANCZOS2_SHARP, 1)
}
開發者ID:rosylilly,項目名稱:gofu,代碼行數:13,代碼來源:image.go

示例2: resize

func resize(mw *imagick.MagickWand, geo btcdn.GeoBox) (err error) {
	var height uint
	width := geo.Width()
	baseWidth := int(mw.GetImageWidth())
	if width > baseWidth {
		width = baseWidth
	}

	if geo.Mode() == "!" {
		height = uint(geo.Height())
	} else {
		ratio := heightToWidthRatio(mw)
		height = uint((float64)(width) * ratio)
	}

	err = mw.ResizeImage(uint(width), height, imagick.FILTER_LANCZOS, 1)
	if err != nil {
		return
	}

	return
}
開發者ID:bootic,項目名稱:btcdn,代碼行數:22,代碼來源:adapter.go

示例3: resizeImage

func resizeImage(wand *imagick.MagickWand, size int, mozaic bool) *imagick.MagickWand {
	width := float32(wand.GetImageWidth())
	height := float32(wand.GetImageHeight())
	var rate float32
	if width > height {
		rate = float32(size) / width
	} else {
		rate = float32(size) / height
	}
	if mozaic {
		wand.ResizeImage(uint(width*rate/20), uint(height*rate/20), imagick.FILTER_LANCZOS, 1)
		wand.ResizeImage(uint(width*rate), uint(height*rate), imagick.FILTER_POINT, 1)
	} else {
		wand.ResizeImage(uint(width*rate), uint(height*rate), imagick.FILTER_LANCZOS, 1)
	}
	return wand.GetImage()
}
開發者ID:dlwr,項目名稱:copyright-protector,代碼行數:17,代碼來源:main.go

示例4: 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.ResizeImage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。