Coder Social home page Coder Social logo

tanktim68 / text2img Goto Github PK

View Code? Open in Web Editor NEW

This project forked from iwark/text2img

0.0 0.0 0.0 10 KB

text2img is a go (golang) package which lets you generate an image from a text. It's especially useful to generate OG images.

Makefile 9.06% Go 90.94%

text2img's Introduction

text2img

GoDoc License

package text2img lets you generate an image from a text. It's especially useful to generate OG images.

Example

Installation

Binary

If you use text2img from your command line, install the binary from releases.

Or use go get:

go get github.com/Iwark/text2img/cmd/text2img

Go code

If you use text2img from your go code, install the package by go get.

$ go get github.com/Iwark/text2img

Usage

Binary

When using a random color background image:

$ text2img -fontpath="fonts/font.ttf" -output="test.jpg" -text="text2img generates the image from a text"

Using a specific image file:

$ text2img -fontpath="fonts/font.ttf" -output="test.jpg" -text="text2img generates the image from a text" -bgimg="gophers.jpg"

bgimgEx

(The Go gopher was designed by Renée French.)

Go code

You can use this package as follows:

package main

import (
  "image/jpeg"
  "os"

  "github.com/Iwark/text2img"
)

func main() {
  path := "fonts/font.ttf"
  d, err := text2img.NewDrawer(text2img.Params{
    FontPath: path,
  })
  checkError(err)

  img, err := d.Draw("text2img generates the image from a text")
  checkError(err)

  file, err := os.Create("test.jpg")
  checkError(err)
  defer file.Close()

  err = jpeg.Encode(file, img, &jpeg.Options{Quality: 100})
  checkError(err)
}

More usage can be found at the godoc.

License

This package is released under the MIT License.

text2img's People

Contributors

iwark avatar yaminoma avatar po3rin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.