Primera subida
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# ignorar imagenes en formato .webp
|
||||
webp/*
|
||||
|
1
animal.png
Symbolic link
@ -0,0 +1 @@
|
||||
imagenes/pinguino.png
|
BIN
fuentes/Bebas.ttf
Normal file
BIN
fuentes/Hand.ttf
Normal file
BIN
fuentes/Roboto.ttf
Normal file
BIN
fuentes/Sketch.ttf
Normal file
10
go.mod
Normal file
@ -0,0 +1,10 @@
|
||||
module portada
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/fogleman/gg v1.3.0
|
||||
|
||||
require (
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||
golang.org/x/image v0.15.0 // indirect
|
||||
)
|
6
go.sum
Normal file
@ -0,0 +1,6 @@
|
||||
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
|
||||
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||
golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8=
|
||||
golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
|
BIN
imagenes/abisal.png
Executable file
After Width: | Height: | Size: 1.6 MiB |
BIN
imagenes/araña.png
Executable file
After Width: | Height: | Size: 1.8 MiB |
BIN
imagenes/atun.png
Executable file
After Width: | Height: | Size: 834 KiB |
BIN
imagenes/avestruz.png
Executable file
After Width: | Height: | Size: 1.8 MiB |
BIN
imagenes/avispa.png
Executable file
After Width: | Height: | Size: 1.0 MiB |
BIN
imagenes/ballena.png
Executable file
After Width: | Height: | Size: 1.7 MiB |
BIN
imagenes/buho.png
Executable file
After Width: | Height: | Size: 1.8 MiB |
BIN
imagenes/burro.png
Executable file
After Width: | Height: | Size: 1.9 MiB |
BIN
imagenes/caballo.png
Executable file
After Width: | Height: | Size: 1.3 MiB |
BIN
imagenes/camaleon.png
Executable file
After Width: | Height: | Size: 2.0 MiB |
BIN
imagenes/cangrejo.png
Executable file
After Width: | Height: | Size: 2.4 MiB |
BIN
imagenes/canguro.png
Executable file
After Width: | Height: | Size: 1.7 MiB |
BIN
imagenes/castor.png
Executable file
After Width: | Height: | Size: 1.6 MiB |
BIN
imagenes/cebra.png
Executable file
After Width: | Height: | Size: 1.4 MiB |
BIN
imagenes/ciervo.png
Executable file
After Width: | Height: | Size: 1.5 MiB |
BIN
imagenes/cocodrilo.png
Executable file
After Width: | Height: | Size: 1.5 MiB |
BIN
imagenes/elefante.png
Executable file
After Width: | Height: | Size: 951 KiB |
BIN
imagenes/escarabajo.png
Executable file
After Width: | Height: | Size: 1.3 MiB |
BIN
imagenes/gallo.png
Executable file
After Width: | Height: | Size: 2.4 MiB |
BIN
imagenes/ganso.png
Executable file
After Width: | Height: | Size: 2.0 MiB |
BIN
imagenes/gato.png
Executable file
After Width: | Height: | Size: 1.6 MiB |
BIN
imagenes/gatoenfadado.png
Executable file
After Width: | Height: | Size: 2.3 MiB |
BIN
imagenes/gerbil.png
Executable file
After Width: | Height: | Size: 1.9 MiB |
BIN
imagenes/gorila.png
Executable file
After Width: | Height: | Size: 3.7 MiB |
BIN
imagenes/jerbo.png
Executable file
After Width: | Height: | Size: 1.1 MiB |
BIN
imagenes/jirafa.png
Executable file
After Width: | Height: | Size: 2.7 MiB |
BIN
imagenes/koala.png
Executable file
After Width: | Height: | Size: 1.2 MiB |
BIN
imagenes/lemur.png
Executable file
After Width: | Height: | Size: 3.1 MiB |
BIN
imagenes/llama.png
Executable file
After Width: | Height: | Size: 2.5 MiB |
BIN
imagenes/loro.png
Executable file
After Width: | Height: | Size: 818 KiB |
BIN
imagenes/mapache.png
Executable file
After Width: | Height: | Size: 1.7 MiB |
BIN
imagenes/mariposa.png
Executable file
After Width: | Height: | Size: 1.2 MiB |
BIN
imagenes/medusa.png
Executable file
After Width: | Height: | Size: 2.5 MiB |
BIN
imagenes/murcielago.png
Executable file
After Width: | Height: | Size: 2.3 MiB |
BIN
imagenes/nutria.png
Executable file
After Width: | Height: | Size: 1.6 MiB |
BIN
imagenes/orangutan.png
Executable file
After Width: | Height: | Size: 2.2 MiB |
BIN
imagenes/oso.png
Executable file
After Width: | Height: | Size: 2.2 MiB |
BIN
imagenes/paloma.png
Executable file
After Width: | Height: | Size: 1.4 MiB |
BIN
imagenes/pavo.png
Executable file
After Width: | Height: | Size: 1.2 MiB |
BIN
imagenes/perro.png
Executable file
After Width: | Height: | Size: 2.9 MiB |
BIN
imagenes/perro2.png
Executable file
After Width: | Height: | Size: 1.8 MiB |
BIN
imagenes/pezluna.png
Executable file
After Width: | Height: | Size: 1.8 MiB |
BIN
imagenes/pezvolador.png
Executable file
After Width: | Height: | Size: 1.1 MiB |
BIN
imagenes/pinguino.png
Executable file
After Width: | Height: | Size: 2.7 MiB |
BIN
imagenes/pterodactilo.png
Executable file
After Width: | Height: | Size: 2.2 MiB |
BIN
imagenes/pulpo.png
Executable file
After Width: | Height: | Size: 924 KiB |
BIN
imagenes/puma.png
Executable file
After Width: | Height: | Size: 1.2 MiB |
BIN
imagenes/rana.png
Executable file
After Width: | Height: | Size: 2.7 MiB |
BIN
imagenes/rape.png
Executable file
After Width: | Height: | Size: 2.1 MiB |
BIN
imagenes/raya.png
Executable file
After Width: | Height: | Size: 720 KiB |
BIN
imagenes/siluro.png
Executable file
After Width: | Height: | Size: 1.9 MiB |
BIN
imagenes/tiburon.png
Executable file
After Width: | Height: | Size: 458 KiB |
BIN
imagenes/tigre.png
Executable file
After Width: | Height: | Size: 2.9 MiB |
BIN
imagenes/toro.png
Executable file
After Width: | Height: | Size: 1.3 MiB |
BIN
imagenes/tortuga.png
Executable file
After Width: | Height: | Size: 1.0 MiB |
BIN
imagenes/vaca.png
Executable file
After Width: | Height: | Size: 1.5 MiB |
BIN
imagenes/zorro.png
Executable file
After Width: | Height: | Size: 1.6 MiB |
218
portada.go
Normal file
@ -0,0 +1,218 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/fogleman/gg"
|
||||
"image"; "image/png"; "image/color"
|
||||
"fmt"; "os"
|
||||
"bufio"; "strings"
|
||||
"math/rand"; "time"
|
||||
)
|
||||
|
||||
|
||||
// Pagina A4 (2480 x 3508)
|
||||
var pagAncho = 2480
|
||||
var pagAlto = 3508
|
||||
var portada = gg.NewContext(pagAncho, pagAlto) // Tamaño de Portada A4 para la Imagen (Ancho x Alto)
|
||||
|
||||
var colorTema = color.RGBA{60, 92, 153, 255} // Color del Tema del Libro (defectoa es Azul)
|
||||
var colorRojo = color.RGBA{202, 31, 0, 255}
|
||||
var colorVerde = color.RGBA{29, 149, 27, 255}
|
||||
var colorAzul = color.RGBA{60, 92, 153, 255} // Azul con transparencia
|
||||
var colorAmarillo = color.RGBA{223, 217, 26, 255}
|
||||
var colorBlanco = color.RGBA{255, 255, 255, 255} // Blanco con transparencia
|
||||
var colorNegro = color.RGBA{0, 0, 0, 255} // Negro con transparencia
|
||||
var colorTextoTitulo = (color.RGBA{255, 255, 255, 230}) // Blanco con transparencia reducida
|
||||
var colorTextoResumen = (color.RGBA{0, 0, 0, 230}) // Negro con transparencia reducida
|
||||
var AltoAreaTitulo = 920 // Altura en pixeles del Area de Titulo
|
||||
|
||||
func main() {
|
||||
|
||||
// Generador de Portadas de Libro
|
||||
fmt.Println("GENERADOR DE PORTADAS PARA LIBROS")
|
||||
|
||||
// Pedir datos
|
||||
leer := bufio.NewReader(os.Stdin)
|
||||
|
||||
fmt.Println("Título: ")
|
||||
inTitulo, _ := leer.ReadString('\n')
|
||||
inTitulo = strings.Replace(inTitulo, "\n", "", -1)
|
||||
|
||||
fmt.Println("SubTítulo: ")
|
||||
inSubtitulo, _ := leer.ReadString('\n')
|
||||
inSubtitulo = strings.Replace(inSubtitulo, "\n", "", -1)
|
||||
|
||||
fmt.Println("Autor: ")
|
||||
inAutor, _ := leer.ReadString('\n')
|
||||
inAutor = strings.Replace(inAutor, "\n", "", -1)
|
||||
|
||||
fmt.Println("Editorial: ")
|
||||
inEditorial, _ := leer.ReadString('\n')
|
||||
inEditorial = strings.Replace(inEditorial, "\n", "", -1)
|
||||
|
||||
// Color Portada
|
||||
fmt.Println("Color de Portada [ N:Negro, R:Rojo, V:Verde, A:Azul, M:Amarillo ] ")
|
||||
inColor, _ := leer.ReadString('\n')
|
||||
inColor = strings.Replace(inColor, "\n", "", -1)
|
||||
switch inColor {
|
||||
case "N": // Negro
|
||||
colorTema = colorNegro
|
||||
//colorTema = color.RGBA{0, 0, 0, 255}
|
||||
case "R": // Rojo
|
||||
colorTema = colorRojo
|
||||
//colorTema = color.RGBA{202, 31, 0, 255}
|
||||
case "V": // Verde
|
||||
colorTema = colorVerde
|
||||
//colorTema = color.RGBA{29, 149, 27, 255}
|
||||
case "A": // Azul
|
||||
colorTema = colorAzul
|
||||
//colorTema = color.RGBA{60, 92, 153, 255}
|
||||
case "M": // Amarillo
|
||||
colorTema = colorAmarillo
|
||||
//colorTema = color.RGBA{223, 217, 26, 255}
|
||||
default: // defecto es Azul
|
||||
colorTema = color.RGBA{60, 92, 153, 255}
|
||||
}
|
||||
|
||||
fmt.Println("Generando Portada. Espere por favor....")
|
||||
|
||||
|
||||
// Fondo portada (x, y, ancho/width, alto/height)
|
||||
DibujaRectanguloColor(colorBlanco, 0, 0, portada.Width(), portada.Height())
|
||||
//DibujaRectanguloColor(colorAzul, 0, 200, portada.Width(), AltoAreaTitulo)
|
||||
DibujaRectanguloColor(colorTema, 0, 200, portada.Width(), AltoAreaTitulo)
|
||||
|
||||
// Localizar imagen deseada (animal.png -es un link de imagen-). Si no existe escoger imagen al azar
|
||||
if _, err := os.Stat("./animal.png"); err == nil {
|
||||
LeerIncluirImagen("./animal.png", 200, AltoAreaTitulo+400)
|
||||
} else {
|
||||
// imagen random
|
||||
f, err := os.Open("./imagenes")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
files, err := f.Readdir(0)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// Random
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
min := 0
|
||||
max := len(files)-1
|
||||
posRandom := rand.Intn(max - min) + min
|
||||
LeerIncluirImagen("./imagenes/"+files[posRandom].Name(), 200, AltoAreaTitulo+400)
|
||||
}
|
||||
|
||||
PonerTextoTitulo(inTitulo, 150, 135)
|
||||
PonerTextoResumen(inSubtitulo, 150, 72)
|
||||
|
||||
PonerTextoEditorial(inEditorial, 100)
|
||||
PonerTextoAutor(inAutor, 72)
|
||||
|
||||
// Banda superior
|
||||
DibujaRectanguloColor(colorTema, 60, 0, portada.Width()-120, 20)
|
||||
// Banda inferior
|
||||
DibujaRectanguloColor(colorTema, 60, pagAlto-20, portada.Width()-120, 20)
|
||||
|
||||
portada.SavePNG("portada.png")
|
||||
fmt.Println("Se ha generado 'portada.png")
|
||||
}
|
||||
|
||||
|
||||
func DibujaRectanguloColor(c color.Color, x, y, w, h int) {
|
||||
portada.SetColor(c)
|
||||
portada.DrawRectangle(float64(x), float64(y), float64(w), float64(h))
|
||||
portada.Fill()
|
||||
}
|
||||
|
||||
func LeerIncluirImagen(fichImagen string, x, y int) {
|
||||
backgroundImage, err := gg.LoadImage(fichImagen)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
portada.DrawImage(backgroundImage, x, y)
|
||||
}
|
||||
|
||||
func PonerTextoTitulo(titulo string, margin int, size int) {
|
||||
// Leer el fichero de la fuente ttf y fijar tamaño fuente
|
||||
if err := portada.LoadFontFace("./fuentes/Roboto.ttf", float64(size)); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Fijar color del texto y mostrar el titulo
|
||||
// usando un margen definido - centrando el texto mostrado
|
||||
// area con el Area del Titulo
|
||||
portada.SetColor(colorTextoTitulo)
|
||||
portada.DrawStringWrapped(titulo,
|
||||
float64(portada.Width())/2, float64(AltoAreaTitulo)/2+200, // x, y
|
||||
0.5, 0.5,
|
||||
float64(portada.Width()-(margin*2)),
|
||||
1.5, // alto linea
|
||||
gg.AlignLeft)
|
||||
}
|
||||
|
||||
func PonerTextoResumen(resumen string, margin int, size int) {
|
||||
// Leer el fichero de la fuente ttf y fijar tamaño fuente
|
||||
if err := portada.LoadFontFace("./fuentes/Roboto.ttf", float64(size)); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Fijar color del texto y mostrar el titulo
|
||||
// usando un margen definido - centrando el texto mostrado
|
||||
// area con el Area del Titulo
|
||||
portada.SetColor(colorTextoResumen)
|
||||
portada.DrawStringWrapped(resumen,
|
||||
float64(portada.Width())/2, float64(80), // x, y
|
||||
0.5, 0.5,
|
||||
float64(portada.Width()-(margin*2)),
|
||||
1.5, // alto linea
|
||||
gg.AlignLeft)
|
||||
}
|
||||
|
||||
|
||||
func PonerTextoAutor(autor string, size int) {
|
||||
// Leer el fichero de la fuente ttf y fijar tamaño fuente
|
||||
if err := portada.LoadFontFace("./fuentes/Bebas.ttf", float64(size)); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
// Fijar color y situarlo (si amarillo autor en negro)
|
||||
if colorTema == colorAmarillo {
|
||||
portada.SetColor(colorNegro)
|
||||
} else {
|
||||
portada.SetColor(colorTema)
|
||||
}
|
||||
portada.DrawString(autor, float64(pagAncho/3*2), float64(pagAlto-130))
|
||||
}
|
||||
|
||||
|
||||
func PonerTextoEditorial(editorial string, size int) {
|
||||
// Leer el fichero de la fuente ttf y fijar tamaño fuente
|
||||
if err := portada.LoadFontFace("./fuentes/Sketch.ttf", float64(size)); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
// Fijar color y situarlo
|
||||
portada.SetColor(colorTema)
|
||||
portada.DrawString(editorial, float64(140), float64(pagAlto-130))
|
||||
}
|
||||
|
||||
func SavePNG(imagen image.Image, fichero string) error {
|
||||
f, err := os.Create(fichero)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
if err := png.Encode(f, imagen); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
BIN
portada.png
Normal file
After Width: | Height: | Size: 2.5 MiB |