fix typos

add routine for resizing an image using imagick
This commit is contained in:
lordwelch 2016-02-03 16:14:11 -08:00
parent 9f56d84854
commit a244345b54
2 changed files with 56 additions and 1 deletions

54
magickwand.go Normal file
View File

@ -0,0 +1,54 @@
// magickwand.go
package main
import (
"math"
"github.com/gographics/imagick/imagick"
)
func resizeImage(mw *imagick.MagickWand, newWidth, newHeight int, keepExactSize, center bool) (resmw *imagick.MagickWand) {
var (
width, height int
)
origHeight := int(mw.GetImageHeight())
origWidth := int(mw.GetImageWidth())
if (origHeight != newHeight) || (origWidth != newWidth) {
if (round((origHeight / origWidth) * newWidth)) <= newHeight {
height = round((float64(origHeight) / float64(origWidth))) * newWidth
width = newWidth
} else {
width = round((float64(origWidth) / float64(origHeight))) * newHeight
height = newHeight
}
} else {
height = newHeight
width = newWidth
}
if !keepExactSize {
resmw.SetSize(width, height)
center = false
} else {
resmw.SetSize(newWidth, newHeight)
if center {
err = mw.ResizeImage(width, height, imagick.FILTER_LANCZOS, 1)
if err != nil {
panic(err)
}
resmw.CompositeImage(mw, imagick.COMPOSITE_OP_SRC_OVER, uint((width-newWidth)/2), uint((height-newHeight)/2))
} else {
resmw.CompositeImage(mw, imagick.COMPOSITE_OP_SRC_OVER, 0, 0)
}
}
mw.Destroy()
return
}
func round(a float64) int {
if a < 0 {
return int(math.Ceil(a - 0.5))
}
return int(math.Floor(a + 0.5))
}

View File

@ -53,6 +53,7 @@ func main() {
}*/ }*/
func run() error { func run() error {
var mainQml qml.Object
engine := qml.NewEngine() engine := qml.NewEngine()
path, err = osext.ExecutableFolder() path, err = osext.ExecutableFolder()
@ -142,7 +143,7 @@ func glInit() {
func setSignals() { func setSignals() {
textEdit.ObjectByName("textEdit1").On("focusChanged", func(focus bool) { textEdit.ObjectByName("textEdit1").On("focusChanged", func(focus bool) {
var ( var (
tr string str string
cel cell cel cell
) )