Giter Club home page Giter Club logo

text2image's Introduction

Text2Image

The most useful & easy2use PHP library for converting any text into image
Version : 1.0 Beta
Requirements: PHP-GD

Text2Image was created basically for translating any text information into an image representation.
And the point is, that there are no other libs for this task, at least there are no such easy4use libs for such tasks.
So all you need is require header file of this lib, create an instance and call "output" or "save" function, that's it! :)

###About modes There is exactly 2 modes in it, "Simple" and "Smart".
The main difference between them is that "Simple" is a lot faster than "Smart".
But, "Simple" mode not support's text-size and angle params.
Also, to use custom fonts in "Simple" mode you need to convert them into GDF.
With "Smart" mode you can use any font's you want, of course, if they are supported by GD, for example, TTF work nice.
See "List of all public methods" below for understanding how to switch between this modes.

###List of all public params:

  • $width = 720, // Width of image box, text will be wrapped withing this box [int]
  • $font = 5, // Font name/family, can be integer font index for Simple mode, or path to TrueType font for Smart mode [int] or [string]
  • $line_height = 'auto', // Height between lines, can be integer or 'auto' [int] or [string]
  • $background_color = array(38, 50, 56), // Color of background, can be array of RGB values, or a hex string [array] or [string]
  • $text_color = array(255, 255, 255), // Color of text, can be array of RGB values, or a hex string [array] or [string]
  • $padding = 30, // Padding by all side's [int]
  • $angle = 0, // smart-only Text angle [int]
  • $text_size = 17, // smart-only Font size [int]
  • $user_fonts = array(); // User defined font's

###List of all public methods:

  • get_mode() - Return current mode, true is "Simple", false is "Smart" [boolean]
  • set_mode($mode) - Allows you to switch between modes, accepts "simple" or "smart" string in first parameter
  • get_text() - Return source text
  • set_text($new_text) - Allows you to set new text
  • add_font($label, $path, $[force_mode = null]) - Using this you can easy add any font you want, by adding "label" you can name added font as you want, "path" defines path to you'r font, "force_mode" can be used to force used mode on font load operation (1 is "Simple", 0 is "Smart")
  • get_font($label) - Use this to get loaded font index by it's label, then you can pass this index into "font" param
  • is_imagetype_supported($type) - Return's True if passed type is supported by you'r PHP build, and false if it's not
  • output($type = 'png', $quality = 100) - Output result image into browser
  • save($path, $type = 'png', $quality = 100) - Allows you to save result image into image, "quality" parameter is supported only with 'jpg' or 'png' image types

Also, see "examples" folder for more.

###Basic usage example

<?php

require "../src/magic.class.php"; // manual include, instead you can use composer

$test = new Priler\Text2Image\Magic('Hello world!');
$test->output();

Example output:

fonts example

###Beautiful smart-mode text using angle

<?php

require "../src/magic.class.php"; // manual include, instead you can use composer

$test = new Priler\Text2Image\Magic(
"
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
"
);

// force mode into smart
$test->set_mode('smart');

// load custom font
// smart-mode work's exactly with .TTF, but other font's may also be supported, see PHP GD docs for more info
$test->add_font('MyFont', './assets/foughtknight.ttf');
$test->font = $test->get_font('MyFont');

// also, smart mode supports text-size property and angle property (last one shown in 5th example)
$test->text_size = 20;
//ANGLE GOES HERE
$test->angle = 3;//negative values also supported

// let's change some basic stuff
$test->background_color = '#eee'; // custom background color
$test->text_color = '#FF5370'; // custom text color
$test->padding = 100; // custom padding


// this settings is same as on 4th example
$test->width = 720; // custom width
$test->line_height = 30; // custom line height


$test->output();

line height example

text2image's People

Contributors

priler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

text2image's Issues

Autoload psr-4 do not work in Symfony 3.4 after install Piler/Text2Image with Composer

Hello! Thank you for Text2Image Library!
I have trouble when I download Piler/Text2Image with composer in to my Symfony app.

The Symfony application version 3.4, it was generate with Symfony-CLI 4.7.3, and Priler/Text2Image was installed with composer version 1.9.0.

Autoload psr-4 not work on ubuntu server 18.04 after install Piler/Text2Image library.

I fix it in the fork https://github.com/lamzin-andrey/lamzinforkpilertext2image.

If you will change files structure and names for fix autoload psr-4 in Symfony 3.4, I wil remove my fork.

Best reguards, Andrey.

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.