PHP imagettftext() with korean characters are not working - php

I am trying to generate image with some text and I have wrote following code:
<?php
// Set the content-type
header('Content-Type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = '준수';
// Replace path by your own font path
$font = 'fonts/Walkway Black RevOblique.ttf';
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
Now when I add text with English characters it works but when I used Korean characters is not working and getting this image.
Any idea how to display Korean text?
Thanks

Looks like Walkway Black RevOblique.ttf is not Korean font. Try to download and use Korean one.

Related

Create an image from data details in site

I want to ask on how to create an image based on updated data on my site?
For example like this image:
[![x][1]][1]
The details of the image is get from this url: [Pine][2].
That's the full code:
It's show an image with updated data based on that link.
Can someone show me what I have to find in google for the details like this? what type is this code?
You should use GD library or Imagick(ImageMagick)
Example of image creation with GD
To install or enable already installed GD extension (https://stackoverflow.com/a/44720393/8579824)
<?php
// Set the content-type
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

PHP text to image using stylistc set in OTF font

I'm trying to output a text to image using a font that has 7 stylistic sets. I'm using the code below but can't find how I can use a style in the output. Any advice would be greatly appreciated.
<?php
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'This is a test!';
// Replace path by your own font path
$font = 'joined.otf';
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

Hindi text to Image - words not appearing properly PHP

I want to display hindi words on an image. Here is the code for it, it is working properly but it does not display "chote E ki matra" correctly. Example "अब हिन्दी" is displayed as : http://prntscr.com/8rj8mq
Also hindi.txt file contains these :
अब हिन्दी
मे टाइप
करना बहुत आसान है
Below php script read one line randomly and put it on image and display it. Can someone help me to correct this....
<?php
$word= file("hindi.txt");
$random = rand(0,2);
$text = $word[$random];
header('Content-Type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
// Replace path by your own font path
$font = 'Mangal.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

Make imagettftext accept the whole pwgen -ny input, not just the first password

So I have this:
https://indigodaddy.koding.com/
(Basically straight out of http://us2.php.net/manual/en/function.imagettftext.php)
<?php
// Set the content-type
header('Content-Type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = `../../../bin/pwgen -ny 12`;
// Replace path by your own font path
$font = 'font/DejaVuSans-Bold.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
How would I make the txt to image conversion accept the entire input of pwgen -ny -12? This outputs 6 columns of 12-char passwords, eg, like this: http://pwgen.net/. I want that entire output converted to the png, not just the first password, as it is doing now.
Any ideas?
** Edit, as requested, sample output of pwgen -ny 12:
Uo/thengohy5 phie=Tahw8ko Cohh1seiz]ua ooY#ee4chei) noo}Mioyei5u au$x5Isaigho
aht6vahGia{j aeph8yoh#kuY EeNgees#ae4k boh5yie1Ic\e aiSh5bahp]ai kiex%ahL0Oob
bei|G{ohm8ae Ieth|ee|wee9 koo#R2iZeot" Nai5Phain(ie Oam*ub0thoth quu6Eyimohd-
geeNgool}ee1 Oow5Pie_sija ab#ahcoo8eeJ ahcoe_r6Vae3 pi%wiedeit4A biegh}u#vu6K
euwei.gei9Of ahr?ai2UquaZ ha3eiXee"koo eiLohf*u1sao ave&aqui8Hie oc-a#z'oh1Le
iv$eeX0eo0Wu rel7aGh6gee& baig3ooN%uz, eoj9eGo.haih Aoka4Uizae:r aiG6aiP.iera
IaY?oo0Aibai pekaeth5Aeh% taav*eiK5Soo zohL5haeng?o teT^u3yash3S xudoh%Dai4ph
tho`R\ahd7ae ohf#e9Ceeph7 Uce7ou{woe8o eeb9jo!Y#aep la7Voo.chae7 te;y5Choo4ie
neeZ5out'oo) ze{iw4Aethok fah3Shoh^Re9 Quoo8au%koot xo2chu>Lae0e Shee#g1eibak
que5Og3aiN&e aw(eetooJ5Ei aeV8ging(eib ohGh9Chah[ch ieYiv5gagh-a kahm2yohR%uo
Eiraivi!o}W0 eo0Oot{ai5sh saT[ae2ahj5O Aefae,l5ieth jo0iJ,ai5eih deer9Aigol'i
aet1Ce,za+fi OFi3exoh)ng3 tae7ooGhaim/ nei$V8Ohh!ae eiy~ia4Itoh; Baisish+ai5d
iib+ooHaoj4t Ayac3aiCh>ee ka/eChoosh2c vanu1Zeex#uy phieB(ai8iev Ou|Gh3zuwo,f
ool3AxiNo~ch zai3Eew&ie*w Zee7eey4eJ*o kooree9Va>B5 FaiB-ah8yahK oha4uP3Oth<o
Aegah2aesh.u eiQuuduu>v1M ae5re8yaXuw% gei5rua1Lu/i eeNg3uyaf"ei Ootee|h8Shai
sa6ed0nieF+e aed8rah;Kai4 boghahH]a7ei eiba$Roh5uu' Ook6oonae`th Vai9taer#oo?
aich7ohMoi/d Ohh1ew-aa"xi Eig%ae]jo2ne urooX1iagh|u iiY8reew,i8d eGhee4fahw(a
ieS%ai1ieh4e pun9Ich0jee; Waer_ai1ieph re)Che`xud0A Aek2wioh\a2u deedae0Ai[be
ohr!a4Ohtae* keNai8aes%oh ookiM3uiRei~ fei-Boo2tu3i coo=c4Yie?w8 ThaiN7fe$o"t
ahw[uChae3va Ej5Evaa&Giix seat|eeZ1yae ee5wiengo]Ba Oo2aThu^p!ai ez{i4too8ohD

Outputting image with underlined text using php GD library

What is the best way to display underlined text and output the result as image with GD or any other library?
You can try using the Unicode underline combining character U+0332.
<?php
// Set the content-type
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = "̲U̲d̲e̲r̲l̲i̲n̲e";
// Replace path by your own font path
$font = 'arial.ttf';
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
There are lots of FREE PHP CAPTCHA out there that come with a lot of customization, download one and see what exactly happens behind the scene. Also have a look at this link
HTH
I am using this...
$font = imageloadfont($font_file);
$font_width = ImageFontWidth($font);
$font_height = ImageFontHeight($font);
$str_width = strlen($text)*$font_width;
ImageLine($image, $left, $top+$font_height, $left+$str_width, $top+$font_height, $color);

Categories