Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example with text array #32

Closed
tenq opened this issue Mar 27, 2020 · 3 comments
Closed

Example with text array #32

tenq opened this issue Mar 27, 2020 · 3 comments
Assignees
Labels

Comments

@tenq
Copy link

tenq commented Mar 27, 2020

Hi, I want generate a restaurant menu with front/verse. How I do array with menu items.

Thanks

@joseluisq joseluisq self-assigned this Mar 28, 2020
@joseluisq
Copy link
Owner

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/

@tenq
Copy link
Author

tenq commented Mar 28, 2020

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');
}

`

@joseluisq
Copy link
Owner

In general your example is fine for your requirement.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants