Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Library text_watermark placement. #43

Closed
bitbucket-import opened this issue Aug 19, 2011 · 3 comments
Closed

Image Library text_watermark placement. #43

bitbucket-import opened this issue Aug 19, 2011 · 3 comments

Comments

@bitbucket-import
Copy link

The vertical placement of text when using TTF's seems a bit erratic. On looking through the code for the text_watermark() method in Image_lib.php, I find:

{{{

!php

$fontwidth = $this->wm_font_size-($this->wm_font_size/4);
$fontheight = $this->wm_font_size;
$this->wm_vrt_offset += $this->wm_font_size;
}}}

On my develoment system, I've replaced this with the following using the php imagettfbbox function to determine the boundaries of the text. It seems to give a much more accurate result.

{{{

!php

$wm_text_box = imagettfbbox($this->wm_font_size,0,$this->wm_font_path,$this->wm_text);
$wm_text_width = $wm_text_box[2] - $wm_text_box[0];
$wm_text_height = $wm_text_box[1] - $wm_text_box[7];
$fontheight = $wm_text_height;
$fontwidth = $wm_text_width/strlen($this->wm_text);
$this->wm_vrt_offset += $fontheight;
}}}

@rcstr
Copy link
Contributor

rcstr commented Sep 22, 2011

done!

@YorrickDL
Copy link

There's still a glitch with this code.

Horizontal positioning is perfect, though the vertical position gets messed up.
I've tested this with rendering different letters/words/sentences, only to see them change vertical position by a pixel or two, depending on which letters/words/sentences you use.

Corrected code:

{{{
#!php
$wm_text_box = imagettfbbox($this->wm_font_size,0,$this->wm_font_path,$this->wm_text);
$wm_text_width = $wm_text_box[2] - $wm_text_box[0];
$fontheight = $wm_font_size;
$fontwidth = $wm_text_width/strlen($this->wm_text);
$this->wm_vrt_offset += $fontheight;
}}}

All I did was re-use the original CI font-size code to get the correct vertical bounding box dimensions.

@narfbg
Copy link
Contributor

narfbg commented Feb 11, 2014

Thanks for your efforts guys.

@narfbg narfbg closed this as completed Feb 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants