PHP Imagick Font not Loading

507 views
Skip to first unread message

Contact PlutonMedia

unread,
Nov 9, 2015, 7:09:03 AM11/9/15
to Google App Engine
Hi,

Is there a trick to be able to load a custom font and use compositeImage?

Here is my code :

app.yaml

application: the_name
version
: 1
runtime
: php55
api_version
: 1
threadsafe
: yes


handlers
:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico


- url: /
009\.jpg
  static_files
: 009.jpg
  upload
: 009\.jpg
  application_readable
: true


- url: /RosewoodStdRegular\.otf
  static_files: RosewoodStdRegular.otf
  upload: RosewoodStdRegular\.otf
  mime_type: application/
x-font-otf


- url: /arial\.ttf
  static_files: arial.ttf
  upload: arial\.ttf
  mime_type: application/
x-font-ttf


- url: .*
  script
: main.php



main.php




<?php
try {


 $img
= new Imagick("009.jpg");
 
 $img
->setImageCompressionQuality(100);
 
 
//ADD TEXT
 $text
= array(
 
'width' => 300,
 
'height'=> 80,
 
'x' => 420,
 
'y' => 160,
 
'font' => 'arial.ttf',
 
'color' => 'black',
 
'value' => "Coucou"
 
);
 
 $addText
= new Imagick();
 $addText
->setBackgroundColor("transparent");
 $addText
->setFont($text['font']);
 $addText
->newPseudoImage($text['width'],$text['height'], "Caption:".$text['value'] );
 $addText
->colorizeImage($text['color'],1);
 $img
->compositeImage($addText, Imagick::COMPOSITE_OVER, $text['x'], $text['y']);
 
 
 
 $img
->setImageFormat('jpg');
 
//header('Content-Type: image/jpg');
 
//echo $img;
 
} catch (Exception $e) {
    echo
'Caught exception: ',  $e->getMessage(), "\n";
}









But I get 

Caught exception: The given font is not found in the ImageMagick configuration and the file (app_path/1.388444744529109221/arial.ttf) is not accessible



Nick (Cloud Platform Support)

unread,
Nov 9, 2015, 4:55:50 PM11/9/15
to Google App Engine
It seems as though the font can't be found at the path specified. Could you use PHP dir() functionality to explore the app_path/1.388444744529109221 directory and see whether arial.ttf is within a subdirectory?

Nick (Cloud Platform Support)

unread,
Nov 9, 2015, 4:56:44 PM11/9/15
to Google App Engine
(that would be scandir())


On Monday, November 9, 2015 at 7:09:03 AM UTC-5, Contact PlutonMedia wrote:

Contact PlutonMedia

unread,
Nov 10, 2015, 4:48:01 AM11/10/15
to Google App Engine
Hi Nick and thank you for your help,

I changed some things (It's working well on localhost).

So using Imagick to load an image works, but when trying to write text on it I get the 500 Internal server error.

Do you know if someone succeeded in writing text on an image using Imagick ?

Best regards

Nick (Cloud Platform Support)

unread,
Nov 10, 2015, 1:40:18 PM11/10/15
to Google App Engine
So, the 500 error is due to the error you reported above, which explains that it can't find the .ttf file. If the function exists, surely it's meant to be used, and surely many people have used it successfully. The issue isn't that nobody has written text on an image using Imagick, it's that in your case, arial.ttf is not where you think it is. As suggested in my last message, why not make calls to scandir() and determine where arial.ttf really is?

Mars Lan

unread,
Nov 10, 2015, 2:27:12 PM11/10/15
to Google App Engine
Have you tried adding "application_readable" to arial.ttf? https://cloud.google.com/appengine/docs/php/config/appconfig#application_readable

Nick (Cloud Platform Support)

unread,
Nov 10, 2015, 2:39:18 PM11/10/15
to Google App Engine
Ahh, I can't believe I had missed that. This is highly likely to be the solution I think.

Contact PlutonMedia

unread,
Nov 11, 2015, 4:30:35 AM11/11/15
to Google App Engine
Hi,

Yes my app.yaml is as follow :


application: image-generator-1124
version: 1
runtime: php55
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /009\.jpg
  static_files: 009.jpg
  upload: 009\.jpg
  application_readable: true

- url: /arial\.ttf
  static_files: arial.ttf
  upload: arial\.ttf
  mime_type: application/x-font-truetype
  application_readable: true

- url: .*
  script: main.php

The scandir output is : 

Array
(
    [0] => .
    [1] => ..
    [2] => 009.jpg
    [3] => app.yaml
    [4] => arial.ttf
    [5] => main.php
    [6] => php.ini
)


Still getting the error

Nick (Cloud Platform Support)

unread,
Nov 11, 2015, 6:40:49 PM11/11/15
to Google App Engine
I suggest at this point that you open a public issue tracker issue, including a .zip of your app (possibly simplified) which is sufficient to reproduce the issue and observe it. This forum isn't meant for specific-issue, one-on-one technical support, but should function as a more general discussion forum for the platform and services. If you post to the public issue tracker, you'll be posting in the correct manner to have this looked-at with an eye to a solution.
Reply all
Reply to author
Forward
0 new messages