Compare commits
No commits in common. "dcff8cd18e191eec4c4fbf68b7959fe7406aa957" and "42c154903a3264fc677e170a91826883af746965" have entirely different histories.
dcff8cd18e
...
42c154903a
39
banner.go
39
banner.go
@ -91,7 +91,8 @@ func getTextBounds(text []string, size float64) (width, height int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func rectsOverlap(r1, r2 struct{ x, y, w, h int }) bool {
|
func rectsOverlap(r1, r2 struct{ x, y, w, h int }) bool {
|
||||||
return !(r1.x+r1.w <= r2.x || r2.x+r2.w <= r1.x || r1.y+r1.h <= r2.y || r2.y+r2.h <= r1.y)
|
return !(r1.x+r1.w <= r2.x || r2.x+r2.w <= r1.x ||
|
||||||
|
r1.y+r1.h <= r2.y || r2.y+r2.h <= r1.y)
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawTextWithOutline(canvas *image.RGBA, text []string, x, y int, textColor, outlineColor color.RGBA, size float64) {
|
func drawTextWithOutline(canvas *image.RGBA, text []string, x, y int, textColor, outlineColor color.RGBA, size float64) {
|
||||||
@ -143,18 +144,7 @@ func drawTextWithOutline(canvas *image.RGBA, text []string, x, y int, textColor,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func abs(a int) int {
|
|
||||||
if a < 0 {
|
|
||||||
return -a
|
|
||||||
}
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
func findTextPositions(textData []*TextData, filename string) {
|
func findTextPositions(textData []*TextData, filename string) {
|
||||||
type attemptedPos struct {
|
|
||||||
x, y int
|
|
||||||
}
|
|
||||||
|
|
||||||
padding := 10
|
padding := 10
|
||||||
|
|
||||||
for i, data := range textData {
|
for i, data := range textData {
|
||||||
@ -182,33 +172,12 @@ func findTextPositions(textData []*TextData, filename string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// track attempted positions to avoid redundancy
|
|
||||||
attempts := make([]attemptedPos, 0, maxPositioningAttempts)
|
|
||||||
|
|
||||||
// min. distance between attempts (1/5 of text height)
|
|
||||||
minAttemptDistance := max(h/5, 10)
|
|
||||||
|
|
||||||
isTooCloseToAttempted := func(x, y int) bool {
|
|
||||||
for _, pos := range attempts {
|
|
||||||
if abs(x-pos.x) < minAttemptDistance && abs(y-pos.y) < minAttemptDistance {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// try random positions
|
// try random positions
|
||||||
for attempt := 0; attempt < maxPositioningAttempts && !placed; attempt++ {
|
for attempt := 0; attempt < maxPositioningAttempts && !placed; attempt++ {
|
||||||
// gen. random pos.
|
// gen. random pos.
|
||||||
x := rand.IntN(maxX-minX+1) + minX
|
x := rand.IntN(maxX-minX+1) + minX
|
||||||
y := rand.IntN(maxY-minY+1) + minY
|
y := rand.IntN(maxY-minY+1) + minY
|
||||||
|
|
||||||
// skip if too close to a previously attempt pos.
|
|
||||||
if isTooCloseToAttempted(x, y) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
attempts = append(attempts, attemptedPos{x: x, y: y})
|
|
||||||
|
|
||||||
// bounding box for cur. text
|
// bounding box for cur. text
|
||||||
curRect := struct{ x, y, w, h int }{
|
curRect := struct{ x, y, w, h int }{
|
||||||
x: x,
|
x: x,
|
||||||
@ -219,7 +188,7 @@ func findTextPositions(textData []*TextData, filename string) {
|
|||||||
|
|
||||||
// checks of overlaps with already placed texts
|
// checks of overlaps with already placed texts
|
||||||
overlaps := false
|
overlaps := false
|
||||||
for j := range i {
|
for j := 0; j < i; j++ {
|
||||||
other := textData[j]
|
other := textData[j]
|
||||||
if !other.Positioned {
|
if !other.Positioned {
|
||||||
continue
|
continue
|
||||||
@ -276,7 +245,7 @@ func findTextPositions(textData []*TextData, filename string) {
|
|||||||
totalOverlapArea := 0
|
totalOverlapArea := 0
|
||||||
|
|
||||||
// calculate total overlap area with existing texts
|
// calculate total overlap area with existing texts
|
||||||
for j := range i {
|
for j := 0; j < i; j++ {
|
||||||
other := textData[j]
|
other := textData[j]
|
||||||
if !other.Positioned {
|
if !other.Positioned {
|
||||||
continue
|
continue
|
||||||
|
28
main.go
28
main.go
@ -38,29 +38,9 @@ type BannerInfo struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
config = Config{
|
config = Config{
|
||||||
ClearwebURL: "https://example.com",
|
ClearwebURL: "https://example.com",
|
||||||
OnionURL: "http://example.onion",
|
OnionURL: "http://example.onion",
|
||||||
ColorThemes: []string{
|
ColorThemes: []string{"vibrant", "sunset", "ocean", "neon", "forest", "cosmic"},
|
||||||
"vibrant",
|
|
||||||
"sunset",
|
|
||||||
"ocean",
|
|
||||||
"neon",
|
|
||||||
"cosmic",
|
|
||||||
"midnight",
|
|
||||||
"fire",
|
|
||||||
"pastel",
|
|
||||||
"earth",
|
|
||||||
"ice",
|
|
||||||
"autumn",
|
|
||||||
"cyberpunk",
|
|
||||||
"retro",
|
|
||||||
"monochrome",
|
|
||||||
"tropical",
|
|
||||||
"volcanic",
|
|
||||||
"aurora",
|
|
||||||
"desert",
|
|
||||||
"matrix",
|
|
||||||
},
|
|
||||||
MaxBanners: 50,
|
MaxBanners: 50,
|
||||||
BannerWidth: 600,
|
BannerWidth: 600,
|
||||||
BannerHeight: 120,
|
BannerHeight: 120,
|
||||||
@ -107,7 +87,7 @@ func main() {
|
|||||||
NewTextData(config.ClearwebURL, defaultFontSize+4.0, false),
|
NewTextData(config.ClearwebURL, defaultFontSize+4.0, false),
|
||||||
}
|
}
|
||||||
|
|
||||||
for range 25 {
|
for range 10 {
|
||||||
if err := genBanner(textData); err != nil {
|
if err := genBanner(textData); err != nil {
|
||||||
log.Errorf("Error generating banner: %s", err)
|
log.Errorf("Error generating banner: %s", err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user