Skip to content

Commit

Permalink
Fix typo in readme. Reorganize image package after pull comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vegardengen committed Oct 14, 2018
1 parent ce716e0 commit d9f1183
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 69 deletions.
12 changes: 12 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PKG := github.com/michael1011/lightningtip

# Enable image support via ImageMagicks MagickWand API. Requires MagickWand C API to be installed
# IMAGICK := -tags imagick
IMAGICK := -tags imagick
GOBUILD := go build -v ${IMAGICK}
GOINSTALL := go install -v
GOINSTALL := go install -v ${IMAGICK}

GO_BIN := ${GOPATH}/bin
DEP_BIN := $(GO_BIN)/dep
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ That's it! The only two things you need to take care about is keeping the LND no

First of all make sure [Golang](https://golang.org/) and [Dep](https://github.com/golang/dep) are both correctly installed. Golang version 1.10 or newer is recommended.

If you want to return a picture, make sure you install ImageMagick MagickWand C API. For examnple (Ubuntu/Debian): sudo apt-get install libmagickwand-dev
If you want to return a picture, make sure you install ImageMagick MagickWand C API. For example (Ubuntu/Debian):

sudo apt-get install libmagickwand-dev


To enable it, edit Makefile and enable the line with IMAGICK : = -tags imagick
```
Expand Down
4 changes: 2 additions & 2 deletions backends/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (lnd *LND) InvoiceSettled(rHash string) (settled bool, err error) {
if err != nil {
return false, err
}
_ = image.GenerateImage(hex.EncodeToString(invoice.RHash), invoice.AmtPaid)
_ = image.GenerateImage(hex.EncodeToString(invoice.RHash), invoice.AmtPaid/1000)
return invoice.Settled, err
}

Expand Down Expand Up @@ -129,7 +129,7 @@ func (lnd *LND) SubscribeInvoices(publish PublishInvoiceSettled, rescan RescanPe
}

if invoice.Settled {
_ = image.GenerateImage(hex.EncodeToString(invoice.RHash), invoice.AmtPaid)
_ = image.GenerateImage(hex.EncodeToString(invoice.RHash), invoice.AmtPaid/1000)
log.Debug("Payment request settled: ", invoice.PaymentRequest)
go publish(invoice.PaymentRequest)
}
Expand Down
44 changes: 18 additions & 26 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,15 @@ const (
defaultSTMPUser = ""
defaultSTMPPassword = ""

defaultImageDir = ""
defaultImageURLDir = ""
defaultImageFile = ""
defaultImageTextBeforeAmt = "I paid a random dude"
defaultImageTextAfterAmt = "satoshis with Lightning Network"
defaultImageTextSecondLine = "but all I got was this picture of his dog."
defaultImageTextFirstLineX = 25
defaultImageTextFirstLineY = 165
defaultImageTextSecondLineX = 25
defaultImageTextSecondLineY = 365
defaultImageTextColor = "black"
defaultImageTextFont = "Verdana-Bold-Italic"
defaultImageTextSize = 150
defaultImageDir = ""
defaultImageURLDir = ""
defaultImageFile = ""
defaultImageText = "I paid a random dude {Amount} satoshi\nbut all I got was this picture of his dog"
defaultImageTextX = 25
defaultImageTextY = 165
defaultImageTextColor = "black"
defaultImageTextFont = "Verdana-Bold-Italic"
defaultImageTextSize = 150
)

type helpOptions struct {
Expand Down Expand Up @@ -134,19 +130,15 @@ func initConfig() {
},

Image: &image.Image{
ImageDir: defaultImageDir,
ImageURLDir: defaultImageURLDir,
ImageFile: defaultImageFile,
ImageTextBeforeAmt: defaultImageTextBeforeAmt,
ImageTextAfterAmt: defaultImageTextAfterAmt,
ImageTextSecondLine: defaultImageTextSecondLine,
ImageTextFirstLineX: defaultImageTextFirstLineX,
ImageTextFirstLineY: defaultImageTextFirstLineY,
ImageTextSecondLineX: defaultImageTextSecondLineX,
ImageTextSecondLineY: defaultImageTextSecondLineY,
ImageTextColor: defaultImageTextColor,
ImageTextFont: defaultImageTextFont,
ImageTextSize: defaultImageTextSize,
ImageDir: defaultImageDir,
ImageURLDir: defaultImageURLDir,
ImageFile: defaultImageFile,
ImageText: defaultImageText,
ImageTextX: defaultImageTextX,
ImageTextY: defaultImageTextY,
ImageTextColor: defaultImageTextColor,
ImageTextFont: defaultImageTextFont,
ImageTextSize: defaultImageTextSize,
},

Mail: &notifications.Mail{
Expand Down
26 changes: 5 additions & 21 deletions image/imageimagick.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,9 @@ package image
import (
"gopkg.in/gographics/imagick.v2/imagick"
"strconv"
"strings"
)

// Image type for holding configuration
type Image struct {
ImageDir string `long:"imagedir" description:"Directory where generated images are placed"`
ImageURLDir string `long:"imageurldir" description:"The directory part of the URL where browsers will find the images"`
ImageFile string `long:"imagefile" description:"Full path to the image that will be served"`
ImageTextBeforeAmt string `long:"imagetextbeforeamt" description:"The text on the first line before the amount"`
ImageTextAfterAmt string `long:"imagetextafteramt" description:"The text on the first line after the amount"`
ImageTextSecondLine string `long:"imagetextsecondline" description:"The text on the second line"`
ImageTextFirstLineX float64 `long:"imagetextfirstlinex" description:"X position for start of first line"`
ImageTextFirstLineY float64 `long:"imagetextfirstliney" description:"Y position for start of first line"`
ImageTextSecondLineX float64 `long:"imagetextsecondlinex" description:"X position for start of second line"`
ImageTextSecondLineY float64 `long:"imagetextsecondliney" description:"Y position for start of second line"`
ImageTextColor string `long:"imagetextcolor" description:"Text Color"`
ImageTextFont string `long:"imagetextfont" description:"Text Font"`
ImageTextSize float64 `long:"imagetextsize" description:"Text size (heigth in pixels)"`
}

// ImageCfg is the Configuration variable
var ImageCfg Image

Expand All @@ -42,6 +26,7 @@ func GenerateImage(rHash string, Amount int64) string {
imagick.Initialize()
defer imagick.Terminate()
var imerr error
var text string

mw := imagick.NewMagickWand()
dw := imagick.NewDrawingWand()
Expand All @@ -56,14 +41,13 @@ func GenerateImage(rHash string, Amount int64) string {
dw.SetFont(ImageCfg.ImageTextFont)
dw.SetFontSize(ImageCfg.ImageTextSize)
dw.SetStrokeColor(pw)
dw.Annotation(ImageCfg.ImageTextFirstLineX, ImageCfg.ImageTextFirstLineY,
ImageCfg.ImageTextBeforeAmt+" "+strconv.FormatInt(Amount, 10)+" "+ImageCfg.ImageTextAfterAmt)
dw.Annotation(ImageCfg.ImageTextSecondLineX, ImageCfg.ImageTextSecondLineY, ImageCfg.ImageTextSecondLine)
text = strings.Replace(ImageCfg.ImageText, "{Amount}", strconv.FormatInt(Amount, 10), -1)
dw.Annotation(ImageCfg.ImageTextX, ImageCfg.ImageTextY, text)
mw.DrawImage(dw)
mw.WriteImage(ImageCfg.ImageDir + "/" + rHash + ".jpg")
newWidth := uint(250)
newHeight := uint(mw.GetImageHeight() * newWidth / mw.GetImageWidth())
imerr = mw.ResizeImage(newWidth, newHeight, imagick.FILTER_LANCZOS, 1)
imerr = mw.ResizeImage(newWidth, newHeight, 0, 1)
if imerr != nil {
panic(imerr)
}
Expand Down
17 changes: 0 additions & 17 deletions image/imagenone.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@

package image

// Image type for holding configuration
type Image struct {
ImageDir string `long:"imagedir" description:"Directory where generated images are placed"`
ImageURLDir string `long:"imageurldir" description:"The directory part of the URL where browsers will find the images"`
ImageFile string `long:"imagefile" description:"Full path to the image that will be served"`
ImageTextBeforeAmt string `long:"imagetextbeforeamt" description:"The text on the first line before the amount"`
ImageTextAfterAmt string `long:"imagetextafteramt" description:"The text on the first line after the amount"`
ImageTextSecondLine string `long:"imagetextsecondline" description:"The text on the second line"`
ImageTextFirstLineX float64 `long:"imagetextfirstlinex" description:"X position for start of first line"`
ImageTextFirstLineY float64 `long:"imagetextfirstliney" description:"Y position for start of first line"`
ImageTextSecondLineX float64 `long:"imagetextsecondlinex" description:"X position for start of second line"`
ImageTextSecondLineY float64 `long:"imagetextsecondliney" description:"Y position for start of second line"`
ImageTextColor string `long:"imagetextcolor" description:"Text Color"`
ImageTextFont string `long:"imagetextfont" description:"Text Font"`
ImageTextSize float64 `long:"imagetextsize" description:"Text size (heigth in pixels)"`
}

// ImageCfg is the Configuration variable
var ImageCfg Image

Expand Down
14 changes: 14 additions & 0 deletions image/imagetype.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package image

// Image type for holding configuration
type Image struct {
ImageDir string `long:"imagedir" description:"Directory where generated images are placed"`
ImageURLDir string `long:"imageurldir" description:"The directory part of the URL where browsers will find the images"`
ImageFile string `long:"imagefile" description:"Full path to the image that will be served"`
ImageText string `long:"imagetext" description:"The text. For amount, put {Amount}"`
ImageTextX float64 `long:"imagetextx" description:"X position for start of first line"`
ImageTextY float64 `long:"imagetexty" description:"Y position for start of first line"`
ImageTextColor string `long:"imagetextcolor" description:"Text Color"`
ImageTextFont string `long:"imagetextfont" description:"Text Font"`
ImageTextSize float64 `long:"imagetextsize" description:"Text size (heigth in pixels)"`
}

0 comments on commit d9f1183

Please sign in to comment.