Giter VIP home page Giter VIP logo

Comments (3)

joseluisq avatar joseluisq commented on May 24, 2024 1

Did you try https://joseluisq.github.io/gimage/examples/text-embedding/?
You can create a canvas as base image, then every text that you want to use you can append it to canvas but for each text as well you can adjust the position how to display them in canvas. Check out the Text class too https://joseluisq.github.io/gimage/classes/text/

from gimage.

joseluisq avatar joseluisq commented on May 24, 2024 1

In general your example is fine for your requirement.

So I'm going to close the issue for now.

from gimage.

tenq avatar tenq commented on May 24, 2024

yes, i'm using it. After a few attempts I managed to come up with a code that apparently will serve me. The goal is to pass an array of products (and their respective values) and create an image for sharing on social networks. Look at the code I got (if it's not the best option and I want to suggest changes, thank you), but I'm still starting development.

`
$figure = new Figure(400, 250);
$figure
->setBackgroundColor(47, 42, 39)
->create();

    $final_text = new stdClass();
    $x = 40;
    $y = 20;
    //simulate array
    $products[] = array ('txt'=> 'texto 001');
    $products[] = array ('txt'=> 'texto 004');
    $products[] = array ('txt'=> 'texto 007');
    $products[] = array ('txt'=> 'texto 005');
    $products[] = array ('txt'=> 'texto 006');

    $canvas = new Canvas($figure);

    foreach ($products as $txt) {

      $text = new Text($txt['txt']);
      $y = $y + 30;

      $text
          ->setWidth(400)
          ->setHeight(250)
          ->setAlign('center') // "none" by default
          ->setLineHeight(1.2)
          ->setLeft($x)
          ->setTop($y)
          ->setSize(22)
          ->setColor(255, 255, 255)
          ->setFontface(FCPATH . 'uploads/fonts/Roboto-Black.ttf');

        //$final_text= (object) array_merge((array) $final_text, (array) $text);
         $canvas
        ->append($text);

   }


    $canvas
        ->toPNG()
        ->draw()
        ->output();
        //->save('text.png');
}

`

from gimage.

Related Issues (17)

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.