Skip to content

Commit

Permalink
bugfix #108 line height for wmt text overlay filter
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHeinrich committed Feb 18, 2018
1 parent 2804ac9 commit 181b232
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 3 additions & 1 deletion docs/phpthumb.readme.txt
Expand Up @@ -365,7 +365,7 @@ fltr = filter system. Call as an array as follows:
watermark image will be scaled to fit inside
<r> is rotation angle of overlaid watermark
- "wmt" (WaterMarkText)
[ex: &fltr[]=wmt|<t>|<s>|<a>|<c>|<f>|<o>|<m>|<n>|<b>|<O>|<x>]
[ex: &fltr[]=wmt|<t>|<s>|<a>|<c>|<f>|<o>|<m>|<n>|<b>|<O>|<x>|<h>]
where:
<t> is the text to use as a watermark;
URLencoded Unicode HTMLentities must be used for
Expand Down Expand Up @@ -407,6 +407,8 @@ fltr = filter system. Call as an array as follows:
extended (either 'x' or 'y' (or both, but both
will obscure entire image))
Note: works with TTF fonts only, not built-in
<h> is the scale multiplier for line height/spacing
default is 1.0
- "flip" [ex: &fltr[]=flip|x or &fltr[]=flip|y]
flip image on X or Y axis
- "ric" [ex: &fltr[]=ric|<x>|<y>]
Expand Down
7 changes: 4 additions & 3 deletions phpthumb.class.php
Expand Up @@ -215,7 +215,7 @@ class phpthumb {
public $issafemode = null;
public $php_memory_limit = null;

public $phpthumb_version = '1.7.15-201802100727';
public $phpthumb_version = '1.7.15-201802181529';

//////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -2984,7 +2984,7 @@ public function ApplyFilters() {
break;

case 'wmt': // WaterMarkText
@list($text, $size, $alignment, $hex_color, $ttffont, $opacity, $margin, $angle, $bg_color, $bg_opacity, $fillextend) = explode('|', $parameter, 11);
@list($text, $size, $alignment, $hex_color, $ttffont, $opacity, $margin, $angle, $bg_color, $bg_opacity, $fillextend, $lineheight) = explode('|', $parameter, 12);
$text = ($text ? $text : '');
$size = ($size ? $size : 3);
$alignment = ($alignment ? $alignment : 'BR');
Expand All @@ -2996,13 +2996,14 @@ public function ApplyFilters() {
$bg_color = ($bg_color ? $bg_color : false);
$bg_opacity = ($bg_opacity ? $bg_opacity : 0);
$fillextend = ($fillextend ? $fillextend : '');
$lineheight = ($lineheight ? $lineheight : 1.0);

if (basename($ttffont) == $ttffont) {
$ttffont = $this->realPathSafe($this->config_ttf_directory.DIRECTORY_SEPARATOR.$ttffont);
} else {
$ttffont = $this->ResolveFilenameToAbsolute($ttffont);
}
$phpthumbFilters->WatermarkText($this->gdimg_output, $text, $size, $alignment, $hex_color, $ttffont, $opacity, $margin, $angle, $bg_color, $bg_opacity, $fillextend);
$phpthumbFilters->WatermarkText($this->gdimg_output, $text, $size, $alignment, $hex_color, $ttffont, $opacity, $margin, $angle, $bg_color, $bg_opacity, $fillextend, $lineheight);
break;

case 'blur': // Blur
Expand Down
11 changes: 6 additions & 5 deletions phpthumb.filters.php
Expand Up @@ -1109,7 +1109,7 @@ public function WhiteBalance(&$gdimg, $targetColor='') {
}


public function WatermarkText(&$gdimg, $text, $size, $alignment, $hex_color='000000', $ttffont='', $opacity=100, $margin=5, $angle=0, $bg_color=false, $bg_opacity=0, $fillextend='') {
public function WatermarkText(&$gdimg, $text, $size, $alignment, $hex_color='000000', $ttffont='', $opacity=100, $margin=5, $angle=0, $bg_color=false, $bg_opacity=0, $fillextend='', $lineheight=1.0) {
// text watermark requested
if (!$text) {
return false;
Expand All @@ -1125,6 +1125,7 @@ public function WatermarkText(&$gdimg, $text, $size, $alignment, $hex_color='000
$originOffsetX = 0;
$originOffsetY = 0;
}
$lineheight = min(100.0, max(0.01, (float) $lineheight));

$metaTextArray = array(
'^Fb' => $this->phpThumbObject->getimagesizeinfo['filesize'],
Expand Down Expand Up @@ -1178,7 +1179,7 @@ public function WatermarkText(&$gdimg, $text, $size, $alignment, $hex_color='000
imagettftext($gdimg, $size, $angle, $text_origin_x, $text_origin_y, $letter_color_text, $ttffont, $text);
$text_origin_x += ($text_width + $margin);
}
$text_origin_y += ($text_height + $margin);
$text_origin_y += ($text_height + $margin) * $lineheight;
}

} else {
Expand Down Expand Up @@ -1293,7 +1294,7 @@ public function WatermarkText(&$gdimg, $text, $size, $alignment, $hex_color='000
$this->DebugMessage('WatermarkText() calling imagettftext($gdimg, '.$size.', '.$angle.', '.$text_origin_x.', '.($text_origin_y + $y_offset).', $letter_color_text, '.$ttffont.', '.$line.')', __FILE__, __LINE__);
imagettftext($gdimg, $size, $angle, $text_origin_x, $text_origin_y + $y_offset, $letter_color_text, $ttffont, $line);

$y_offset += $char_height;
$y_offset += $char_height * $lineheight;
}

}
Expand Down Expand Up @@ -1400,8 +1401,8 @@ public function WatermarkText(&$gdimg, $text, $size, $alignment, $hex_color='000
$this->DebugMessage('WatermarkText() calling imagestring($img_watermark, '.$size.', '.$x_offset.', '.($key * imagefontheight($size)).', '.$line.', $text_color_watermark)', __FILE__, __LINE__);
imagestring($img_watermark, $size, $x_offset, $key * imagefontheight($size), $line, $text_color_watermark);
if ($angle && $img_watermark_mask) {
$this->DebugMessage('WatermarkText() calling imagestring($img_watermark_mask, '.$size.', '.$x_offset.', '.($key * imagefontheight($size)).', '.$text.', $mask_color_watermark)', __FILE__, __LINE__);
imagestring($img_watermark_mask, $size, $x_offset, $key * imagefontheight($size), $text, $mask_color_watermark);
$this->DebugMessage('WatermarkText() calling imagestring($img_watermark_mask, '.$size.', '.$x_offset.', '.($key * imagefontheight($size) * $lineheight).', '.$text.', $mask_color_watermark)', __FILE__, __LINE__);
imagestring($img_watermark_mask, $size, $x_offset, $key * imagefontheight($size) * $lineheight, $text, $mask_color_watermark);
}
}
if ($angle && $img_watermark_mask) {
Expand Down

0 comments on commit 181b232

Please sign in to comment.