Welcome Guest, Not a member yet? Register   Sign In
PLEASE HELP UNICODE WATERMARKING IN CODEIGNITER
#1

[eluser]QUYET[/eluser]
Hi,
I am building a function that can watermark the image with text but I have an issue when the text is in French.
This is my code:
function my_watermark() {
$this->load->library('image_lib');
$config['wm_type'] = 'text';
$config['wm_font_path'] = './system/fonts/texb.ttf';
$config['wm_font_size'] = '16';
$config['wm_font_color'] = '333333';
$config['wm_vrt_alignment'] = 'middle';
$config['wm_hor_alignment'] = 'center';
$config['wm_text'] = '255 caractères maximum 255 caractères maximum 255 caractères maximum';
$this->image_lib->initialize($config);
$this->image_lib->watermark();
}

Finally I got all broken for unicode char.
Thanks alot.
Quyet
#2

[eluser]ivantcholakov[/eluser]
Maybe the functions within GD library are not UTF-8 compatible, I am not sure. Anyway, if all the languages in your site are from latin origin, you may try a workaround by converting the text to ISO-8859-15 or ISO-8859-1 encoding.

So, with the line
Code:
$config[‘wm_text’] = ‘255 caractères maximum 255 caractères maximum 255 caractères maximum’;

you may do the following experiments until the text is shown well:

Code:
$config[‘wm_text’] = mb_convert_encoding(‘255 caractères maximum 255 caractères maximum 255 caractères maximum’, 'ISO-8859-15', 'UTF-8');

or

Code:
$config[‘wm_text’] = mb_convert_encoding(‘255 caractères maximum 255 caractères maximum 255 caractères maximum’, 'ISO-8859-1', 'UTF-8');

or

Code:
$config[‘wm_text’] = iconv('UTF-8', 'ISO-8859-15', ‘255 caractères maximum 255 caractères maximum 255 caractères maximum’);

or

Code:
$config[‘wm_text’] = iconv('UTF-8', 'ISO-8859-1', ‘255 caractères maximum 255 caractères maximum 255 caractères maximum’);
#3

[eluser]QUYET[/eluser]
Thanks ivantcholakov,
I did try those but still can not get what I wanted. Font still broken!
Please help!
Regards,
Quyet
#4

[eluser]Ckirk[/eluser]
I think it may be that the GD library used by the codeigniter image_lib doesn't handle certain UTF-8 charcters such as those used in your string.

The following function may be the answer to the problem in that you can prep the text before applying it to wm_text:

Code:
private function prepareText($text){
    $text = mb_convert_encoding($text, "HTML-ENTITIES", "UTF-8");
    $text = preg_replace('~^(&([a-zA-Z0-9]);)~',htmlentities('${1}'),$text);
    return($text);
}

Hope that helps
#5

[eluser]ivantcholakov[/eluser]
I tried to test a text watermark with pure GD functions, but this is what I got: "Message: imagettftext(): Could not find/open font". I am sure that font path is correct.

Ubuntu 13.10, 64-bit, php 5.5.3

Something similar has been reported: http://ellislab.com/forums/viewthread/216459/

I'll make a check with a different font.
#6

[eluser]ivantcholakov[/eluser]
Forget about the error message, it is my mistake.

I downloaded a sample font from here: http://www.fontsupply.com/fonts/T/Times.html

The on a pure GD-implementation I tested what Ckirk suggested. Characters get shown correctly. The simple encoding conversion UTF-8 -> ISO-8859-15 seemingly works too for your example, but maybe there are thinks that I don't know.

But with the font texb.ttf I have no success.

So, change the font, get Ckirk's suggestion and fight again. :-)

An amendment: I played with this simple script "Watermark with Text" with some minor modifications: http://www.9lessons.info/2011/11/php-ima...rmark.html
#7

[eluser]QUYET[/eluser]
Hi ivantcholakov,

Did you use CI's imagelib to create your attached image?
#8

[eluser]ivantcholakov[/eluser]
No, because I use CI 3.
#9

[eluser]QUYET[/eluser]
Thanks,
My project developed from CodeIgniter. I did try all of you guys' suggestion and still can not have proper text.
Appreciate any help
#10

[eluser]ivantcholakov[/eluser]
Tell me, what CodeIgniter version do you use.




Theme © iAndrew 2016 - Forum software by © MyBB