From 43db9e18cc146aa4abafdef18b529b2e788adb55 Mon Sep 17 00:00:00 2001 From: lordwelch Date: Thu, 24 Mar 2016 09:16:15 -0700 Subject: [PATCH] documentaion --- magickwand.go | 13 ++++++++++++- main.go | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/magickwand.go b/magickwand.go index 78da62c..984eb8b 100644 --- a/magickwand.go +++ b/magickwand.go @@ -7,6 +7,11 @@ import ( "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) { var ( width, height, origHeight, origWidth int @@ -14,11 +19,14 @@ func resizeImage(mw *imagick.MagickWand, newWidth, newHeight int, keepSpecSize, origHeight = int(mw.GetImageHeight()) origWidth = int(mw.GetImageWidth()) + //check if requested size is the same as current size if (origHeight != newHeight) || (origWidth != newWidth) { + // width / height * newheight = newwidth if (round((float64(origWidth) / float64(origHeight)) * float64(newHeight))) <= newWidth { width = round((float64(origWidth) / float64(origHeight)) * float64(newHeight)) height = newHeight } else { + // height / width * newwidth = newheight height = round((float64(origHeight) / float64(origWidth)) * float64(newWidth)) width = newWidth } @@ -27,18 +35,21 @@ func resizeImage(mw *imagick.MagickWand, newWidth, newHeight int, keepSpecSize, width = newWidth } + //new magickwand for resized image resmw = imagick.NewMagickWand() + if !keepSpecSize { resmw.NewImage(uint(width), uint(height), imagick.NewPixelWand()) center = false } else { + //blank image resmw.NewImage(uint(newWidth), uint(newHeight), imagick.NewPixelWand()) - //fmt.Println(resmw.GetImageHeight(), resmw.GetImageWidth()) if center { err = mw.ResizeImage(uint(width), uint(height), imagick.FILTER_LANCZOS, 1) if err != nil { panic(err) } + //centers image resmw.CompositeImage(mw, imagick.COMPOSITE_OP_SRC_OVER, round(float64(newWidth-width)/float64(2)), round(float64(newHeight-height)/float64(2))) } else { resmw.CompositeImage(mw, imagick.COMPOSITE_OP_SRC_OVER, 0, 0) diff --git a/main.go b/main.go index 5150fe2..529c0e2 100644 --- a/main.go +++ b/main.go @@ -86,8 +86,10 @@ func run() error { textEdit = window.ObjectByName("textEdit") slides.addCell() + //signals for whole qml setSignals() + //image is ready for imageprovider imgready = true