-
Notifications
You must be signed in to change notification settings - Fork 28
Add support for creating a fun image with text (including the amount of satoshis) #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vegardengen
wants to merge
7
commits into
michael1011:master
Choose a base branch
from
vegardengen:image
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ae4cb82
Added image support.
vegardengen 4732eaf
Make image support configurable and hide it behind build tiag imagick
vegardengen e8229dd
Documentation and Makefile support
vegardengen 4c759e4
Cleanup
vegardengen ce716e0
Revert to standard 0.5 RPC API for LND.
vegardengen 4a22d86
Fix typo in readme. Reorganize image package after pull comments
vegardengen ab308ba
Switch image support off per default.
vegardengen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// +build imagick | ||
|
||
package image | ||
|
||
import ( | ||
"gopkg.in/gographics/imagick.v2/imagick" | ||
"strconv" | ||
) | ||
|
||
// 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"` | ||
vegardengen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
|
||
// SetImageCfg - Set package configuration from outside package | ||
func SetImageCfg(Cfg Image) { | ||
ImageCfg = Cfg | ||
} | ||
|
||
// GetImagePath - Get the web path for the picture based on the payment hash | ||
func GetImagePath(rHash string) string { | ||
return (ImageCfg.ImageURLDir + "/" + rHash + ".jpg") | ||
} | ||
|
||
// GetImagePath - Get the web path for the picture based on the payment hash | ||
func GenerateImage(rHash string, Amount int64) string { | ||
imagick.Initialize() | ||
defer imagick.Terminate() | ||
var imerr error | ||
|
||
mw := imagick.NewMagickWand() | ||
dw := imagick.NewDrawingWand() | ||
pw := imagick.NewPixelWand() | ||
|
||
imerr = mw.ReadImage(ImageCfg.ImageFile) | ||
if imerr != nil { | ||
panic(imerr) | ||
} | ||
pw.SetColor(ImageCfg.ImageTextColor) | ||
dw.SetFillColor(pw) | ||
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) | ||
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) | ||
if imerr != nil { | ||
panic(imerr) | ||
} | ||
mw.WriteImage("/var/www/lnd/tips/" + rHash + ".jpg_small.jpg") | ||
|
||
return GetImagePath(rHash) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// +build !imagick | ||
// Stubs to make code compile and behave same if it has image supportr or not. | ||
|
||
package image | ||
|
||
// Image type for holding configuration | ||
type Image struct { | ||
vegardengen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
|
||
// SetImageCfg - Set package configuration from outside package | ||
func SetImageCfg(Cfg Image) { | ||
ImageCfg = Cfg | ||
} | ||
|
||
// GetImagePath - Get the web path for the picture based on the payment hash | ||
func GetImagePath(rHash string) string { | ||
return ("") | ||
} | ||
|
||
// GenerateImage - Generate a picture from hash and amount | ||
func GenerateImage(rHash string, Amount int64) string { | ||
return ("") | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.