【问题标题】:What is the path for a font symfony字体 symfony 的路径是什么
【发布时间】:2017-02-22 16:25:39
【问题描述】:

我正在尝试做一些文本并将其转换为图像。

我从 php 手册中得到了一些代码。

我正在 symfony 3.1 中处理它

我唯一的问题是你如何设置字体的路径。

roboto-regular.ttf 在我的 /web 目录中。

我的代码:

    //setting the content type
    header('Content-Type: image/png');

    // Create the image
    $im = imagecreatetruecolor(400,30);

    // Create Some colors
    $white = imagecolorallocate($im, 255, 255, 255);
    $grey = imagecolorallocate($im, 128, 128, 128);
    $black = imagecolorallocate($im, 0, 0, 0);
    imagefilledrectangle($im, 0, 0, 399, 29, $white);

    // The text to draw
    $text = 'Testing';
    // Replace path by your font path
    $font = 'Roboto-Regular.ttf';

    // Add some shadow to the text
    imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

    // Add the text
    imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

    // Using imagepng() resulst in clearer text compared with imagejpeg()
    imagepng($im);
    imagedestroy($im);

【问题讨论】:

    标签: php symfony fonts


    【解决方案1】:
    $this->get('request')->getBasePath();
    

    $this->get('request')->getBasePath();会直接把你放到网页目录

    【讨论】:

      【解决方案2】:

      在 Symfony2 中实际上没有直接的方法来获取 webdir 的路径,因为该框架完全独立于 webdir。 但是你可以使用getRootDir():

      $path = $this->get('kernel')->getRootDir() . '/../web';
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-15
        • 2020-10-30
        • 2014-08-02
        • 2020-11-16
        • 1970-01-01
        • 2015-05-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多