2

I downloaded a system and apparently it was created using Smarty Template Engine. I am not familiar with this template engine and i am having a hard time achieving what i want. I want to add text on an image and i found this code:

<?php
      //Set the Content Type
      header('Content-type: image/jpeg');

      // Create Image From Existing File
      $jpg_image = imagecreatefromjpeg('sunset.jpg');

      // Allocate A Color For The Text
      $white = imagecolorallocate($jpg_image, 255, 255, 255);

      // Set Path to Font File
      $font_path = 'font.TTF';

      // Set Text to Be Printed On Image
      $text = "This is a sunset!";

      // Print Text On Image
      imagettftext($jpg_image, 25, 0, 75, 300, $white, $font_path, $text);

      // Send Image to Browser
      imagejpeg($jpg_image);

      // Clear Memory
      imagedestroy($jpg_image);
    ?> 

I searched the web and i found out that Smarty does not allow Php code in TPL files. I tried using {php} //code here {/php} but it does not work. Is there a way to enable php tags in smarty? if not, how can i achieve what i want?

Ronald Torres
  • 199
  • 2
  • 4
  • 19

1 Answers1

0

I think the better approach is to create image in controller then encode image to base64 and send it to view/template.

In your controller

$img = 'created image by image function';

/*encode image to base64 and send it to view/template*/
$img = base64_encode($img);

Now in your view render image with this

<img src="data:image/gif;base64,{ $img }" />
DEarTh
  • 975
  • 1
  • 7
  • 18