documentaion
This commit is contained in:
parent
f0c49df67b
commit
43db9e18cc
@ -7,6 +7,11 @@ import (
|
|||||||
"gopkg.in/gographics/imagick.v2/imagick"
|
"gopkg.in/gographics/imagick.v2/imagick"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*resizeImage() mw fullsize image
|
||||||
|
newwidth, newheight = size to be resized to
|
||||||
|
keepSpecSize = return image with exactly the size specified or just the size of the resized image
|
||||||
|
center = senter the image
|
||||||
|
*/
|
||||||
func resizeImage(mw *imagick.MagickWand, newWidth, newHeight int, keepSpecSize, center bool) (resmw *imagick.MagickWand) {
|
func resizeImage(mw *imagick.MagickWand, newWidth, newHeight int, keepSpecSize, center bool) (resmw *imagick.MagickWand) {
|
||||||
var (
|
var (
|
||||||
width, height, origHeight, origWidth int
|
width, height, origHeight, origWidth int
|
||||||
@ -14,11 +19,14 @@ func resizeImage(mw *imagick.MagickWand, newWidth, newHeight int, keepSpecSize,
|
|||||||
origHeight = int(mw.GetImageHeight())
|
origHeight = int(mw.GetImageHeight())
|
||||||
origWidth = int(mw.GetImageWidth())
|
origWidth = int(mw.GetImageWidth())
|
||||||
|
|
||||||
|
//check if requested size is the same as current size
|
||||||
if (origHeight != newHeight) || (origWidth != newWidth) {
|
if (origHeight != newHeight) || (origWidth != newWidth) {
|
||||||
|
// width / height * newheight = newwidth
|
||||||
if (round((float64(origWidth) / float64(origHeight)) * float64(newHeight))) <= newWidth {
|
if (round((float64(origWidth) / float64(origHeight)) * float64(newHeight))) <= newWidth {
|
||||||
width = round((float64(origWidth) / float64(origHeight)) * float64(newHeight))
|
width = round((float64(origWidth) / float64(origHeight)) * float64(newHeight))
|
||||||
height = newHeight
|
height = newHeight
|
||||||
} else {
|
} else {
|
||||||
|
// height / width * newwidth = newheight
|
||||||
height = round((float64(origHeight) / float64(origWidth)) * float64(newWidth))
|
height = round((float64(origHeight) / float64(origWidth)) * float64(newWidth))
|
||||||
width = newWidth
|
width = newWidth
|
||||||
}
|
}
|
||||||
@ -27,18 +35,21 @@ func resizeImage(mw *imagick.MagickWand, newWidth, newHeight int, keepSpecSize,
|
|||||||
width = newWidth
|
width = newWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//new magickwand for resized image
|
||||||
resmw = imagick.NewMagickWand()
|
resmw = imagick.NewMagickWand()
|
||||||
|
|
||||||
if !keepSpecSize {
|
if !keepSpecSize {
|
||||||
resmw.NewImage(uint(width), uint(height), imagick.NewPixelWand())
|
resmw.NewImage(uint(width), uint(height), imagick.NewPixelWand())
|
||||||
center = false
|
center = false
|
||||||
} else {
|
} else {
|
||||||
|
//blank image
|
||||||
resmw.NewImage(uint(newWidth), uint(newHeight), imagick.NewPixelWand())
|
resmw.NewImage(uint(newWidth), uint(newHeight), imagick.NewPixelWand())
|
||||||
//fmt.Println(resmw.GetImageHeight(), resmw.GetImageWidth())
|
|
||||||
if center {
|
if center {
|
||||||
err = mw.ResizeImage(uint(width), uint(height), imagick.FILTER_LANCZOS, 1)
|
err = mw.ResizeImage(uint(width), uint(height), imagick.FILTER_LANCZOS, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
//centers image
|
||||||
resmw.CompositeImage(mw, imagick.COMPOSITE_OP_SRC_OVER, round(float64(newWidth-width)/float64(2)), round(float64(newHeight-height)/float64(2)))
|
resmw.CompositeImage(mw, imagick.COMPOSITE_OP_SRC_OVER, round(float64(newWidth-width)/float64(2)), round(float64(newHeight-height)/float64(2)))
|
||||||
} else {
|
} else {
|
||||||
resmw.CompositeImage(mw, imagick.COMPOSITE_OP_SRC_OVER, 0, 0)
|
resmw.CompositeImage(mw, imagick.COMPOSITE_OP_SRC_OVER, 0, 0)
|
||||||
|
2
main.go
2
main.go
@ -86,8 +86,10 @@ func run() error {
|
|||||||
|
|
||||||
textEdit = window.ObjectByName("textEdit")
|
textEdit = window.ObjectByName("textEdit")
|
||||||
slides.addCell()
|
slides.addCell()
|
||||||
|
|
||||||
//signals for whole qml
|
//signals for whole qml
|
||||||
setSignals()
|
setSignals()
|
||||||
|
|
||||||
//image is ready for imageprovider
|
//image is ready for imageprovider
|
||||||
imgready = true
|
imgready = true
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user