Add text on image using SimpleImage by claviska

1.5k Views Asked by At

I am trying to add text withing an image using SimpleImage by claviska(https://github.com/claviska/SimpleImage#texttext-options-boundary).

Here is the error I am getting:

Fatal error: Uncaught Error: Cannot pass parameter 3 by reference in C:\xampp\htdocs\SimpleImage-master\index.php:19 Stack trace: #0 {main} thrown in C:\xampp\htdocs\SimpleImage-master\index.php on line 19

Here is my code

<?php
require 'src/claviska/SimpleImage.php';

try {
  // Create a new SimpleImage object
  $image = new \claviska\SimpleImage();

  $image
    ->fromFile('background.png')                     // load image.jpg
    ->autoOrient()                              // adjust orientation based on exif data
    ->resize(500, 500)                          // resize to 320x200 pixels
    ->flip('x')                                 // flip horizontally
    ->colorize('DarkBlue')                      // tint dark blue
    //->border('black', 10)                       // add a 10 pixel black border

    ->overlay('img.jpg', 'center')  // add a watermark image
    ->toFile('new-image.png', 'image/png')
    ->text('text here', 'font.ttf', 32, '#FFFFFF', 'top', 0, 20)      
    // convert to PNG and save a copy to new-image.png
    ->toScreen();                               // output to the screen


} catch(Exception $err) {
  // Handle errors
  echo $err->getMessage();
}

?>
1

There are 1 best solutions below

0
Britton Pentakill On

Text options need to be passed as an array.

text('text here', array(
'fontFile' => 'font.ttf',
'size' => 32,
'color' => '#FFFFFF',
'anchor' => 'top')
))

There's a complete list of text options from the Claviska GitHub documents: https://github.com/claviska/SimpleImage