【问题标题】:Codeigniter image manipulation text watermark line breaksCodeigniter 图像处理文本水印换行符
【发布时间】:2013-06-06 23:20:28
【问题描述】:

我正在尝试使用 CodeIgniters Image Manipulation 库在图像上添加多行水印,但无法正常工作。

我正在设置文本

$config['source_image']= $newFile;
$str = '';
$str.='Px: ';
$str .= $config['width'];
$str .= "\r\n";
$str.=' | Qual: '.$config['quality'];
$str .= "\n";
$str.=' Size: '.$size;
$str .= "<br />";
$str.=' File: '.$fileName;  
$config['wm_text'] = $str;

文档中没有提及它,我在此处或 Google 上看不到任何有关它的信息。这并不重要 - 这只是一个个人项目,但我希望能够做到。

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    如果您查看 system/libraries 中的 Image_lib.php 类,您会发现它使用了imagettftext 函数:

    imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text);
    

    $y_shadvariable 确定提供的整个文本的垂直偏移量。如果你想要换行符,你必须让你的文本变量是一个数组,然后使用一个 foreach 循环来增加每一行(即数组中的每个项目)的垂直偏移量。

    然而,要实现这一点,您必须彻底改变 CI 的 Image_lib.php 类中的 text_watermark 方法,因为您现在将文本变量作为数组处理,而不是简单的字符串。所以这不是不可能的,而是相当乏味的,因此很可能不值得努力......

    【讨论】:

    • 谢谢@Mudshark。你是对的,仅仅记录关于每张图像的一些统计数据将是太多的工作。我正在尝试许多组合或原始文件大小和分辨率以及许多不同的 CI 设置,以找到适合我的自适应/响应图像的最佳位置
    【解决方案2】:
    function imagettfmultilinetext($image, $size, $angle, $x, $y, $color, $fontfile,  $text, $spacing=1)
    {
        $lines=explode("\n",$text);
        for($i=0; $i< count($lines); $i++)
        {
            $newY=$y+($i * $size * $spacing);
            imagettftext($image, $size, $angle, $x, $newY, $color, $fontfile,  $lines[$i], $spacing);
        }
        return null;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多