fix typos
add routine for resizing an image using imagick
This commit is contained in:
parent
9f56d84854
commit
a244345b54
54
magickwand.go
Normal file
54
magickwand.go
Normal 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))
|
||||
}
|
3
main.go
3
main.go
@ -53,6 +53,7 @@ func main() {
|
||||
}*/
|
||||
|
||||
func run() error {
|
||||
var mainQml qml.Object
|
||||
|
||||
engine := qml.NewEngine()
|
||||
path, err = osext.ExecutableFolder()
|
||||
@ -142,7 +143,7 @@ func glInit() {
|
||||
func setSignals() {
|
||||
textEdit.ObjectByName("textEdit1").On("focusChanged", func(focus bool) {
|
||||
var (
|
||||
tr string
|
||||
str string
|
||||
cel cell
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user