Is there any way or method to convert text (string) to image with javascript or jquery? I cant find any way to do this. Whats the best?
I don't want to use php or asp to do this. Thanks for any tricks and help.
Is there any way or method to convert text (string) to image with javascript or jquery? I cant find any way to do this. Whats the best?
I don't want to use php or asp.net to do this. Thanks for any tricks and help.
Share Improve this question asked Nov 28, 2011 at 7:05 MortezaMorteza 2,1538 gold badges38 silver badges62 bronze badges 4- Why? You can just insert text in your page and have it show as a wide variety of fonts. You don't need it as an image to show it. – jfriend00 Commented Nov 28, 2011 at 7:37
- I need because I have some problem with unicode chars. – Morteza Commented Nov 28, 2011 at 9:43
- Then, you might as well give up doing this client side. If you can't display your unicode text as normal text because of unicode issues, then I have no idea how you're going to draw it into an image client-side because that will have the same issues. My guess is that you really just don't understand how to specify unicode text in HTML and select an appropriate font that has support for it. – jfriend00 Commented Nov 28, 2011 at 20:23
- That's not my problem, I have problem with Bi-directional text, but I found the solution. – Morteza Commented Nov 28, 2011 at 22:15
2 Answers
Reset to default 15Use the canvas
element and draw text onto it.
jsFiddle.
creating image from string with php
<?php
// Create a 100*30 image
$im = imagecreate(100, 30);
// White background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);
// Write the string at the top left
imagestring($im, 5, 0, 0, 'Hello world!', $textcolor);
// Output the image
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
more info here