【问题标题】:Uploading a font and displaying a preview in php/codeigniter上传字体并在 php/codeigniter 中显示预览
【发布时间】:2012-06-04 23:11:58
【问题描述】:

我不太擅长 PHP,但我想知道是否有办法做到这一点。我所拥有的是一个表单,它允许用户上传字体文件,并在上传字体文件后将它们显示在库的下方。我希望它能够实际显示字体在库中的样子。到目前为止,我还没有找到一种方法来做到这一点。这可以用PHP吗?

【问题讨论】:

  • 看看PHP中的图像绘制函数。字体上传到服务器后,您可以在图像生成中使用它。

标签: php image codeigniter fonts upload


【解决方案1】:

对于使用 Code Igniter 的非常快速和肮脏的解决方案,您可以使用图像操作类和图像水印功能。

结帐the documentation of codeigniter 3 它向您展示了如何使用自定义字体应用水印。上传一个纯白色的图片源文件并打开:

$config['image_library'] = 'gd2';
$config['source_image'] = '/path/to/image/mypic.jpg';
$config['maintain_ratio'] = TRUE;
$config['width']     = 75;
$config['height']   = 50;

$this->load->library('image_lib', $config); 

完成后,您可以在图像上绘制水印:

$config['source_image'] = '/path/to/image/mypic.jpg';
$config['wm_text'] = 'Text to Display Here';
$config['wm_type'] = 'text';
$config['wm_font_path'] = './system/fonts/texb.ttf'; // Path to font file
$config['wm_font_size'] = '16';
$config['wm_font_color'] = 'ffffff';
$config['wm_vrt_alignment'] = 'bottom';
$config['wm_hor_alignment'] = 'center';
$config['wm_padding'] = '20';

$this->image_lib->initialize($config); 

$this->image_lib->watermark();

我认为所有内容都在此处(上方)或代码点火器文档页面上进行了解释。

【讨论】:

    猜你喜欢
    • 2011-03-08
    • 1970-01-01
    • 2013-01-22
    • 1970-01-01
    • 2016-07-29
    • 2021-03-28
    • 2012-10-12
    • 1970-01-01
    • 2013-02-14
    相关资源
    最近更新 更多