Yami Medina
Yami Medina

Reputation: 670

Writing text on uploaded image with WideImage

I am working to implement the WideImage plugin on a PHP-based project.

Right now, we have the image upload working (which goes to a temporary folder based on session ID), but no text is written on the image. I was working based off of this example on their website (minus the shadow effect), but it doesn't seem to be doing anything. When I go to the destination folder and look at the uploaded image, there are no changes.

Here is the code snippet; are there any errors that stand out? I recently added the setFont line, but that didn't seem to make a difference.

      require("upload.php");
      $userImagePath = $userFolderPath . $_FILES["fileToUpload"]["name"];

      $newImagePath = null;


      $image = WideImage::loadFromFile($userImagePath);


      $canvas = $image->getCanvas();
      $canvas->setFont('resources/assets/NOVABOLD.otf');


      $canvas->useFont('resources/assets/NOVABOLD.otf', 20, $image->allocateColor(255, 255, 255));          
      $canvas->writeText('center', 'top', 'I am ');

When I use echo $userImagePath, it does give me a working file path.

I've also tried using the fileFromUpload option, but it wouldn't recognize it as an upload even though I gave it the file field's name from the HTML form.

Upvotes: 0

Views: 503

Answers (1)

user11096486
user11096486

Reputation: 1

  $font = '/resources/assets/NOVABOLD.otf';
  $image = WideImage::load('name');

  $canvas = $image->getCanvas();

  $canvas->useFont($font, 20, $image->allocateColor(255, 255, 255));          
  $canvas->writeText('center', 'top', 'I am ');

Upvotes: 0

Related Questions