Is there a php or javascript method of converting a simple html file with text to a JPEG image and saving it automatically. I would like to be able to pull it into Outlook 2007 as "embedded content" for a company's dynamic disclaimer
Any help would be appreciated
UPDATE
i have found the following script that produces a image with only a string:
<?php
$text = "This is a example";
header("Content-Type: image/png");
$im = #imagecreate(700, 300)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 12, 5, 5, $text, $text_color);
imagepng($im);
imagedestroy($im);
?>
Is there a way to get <br> tags to work in a php string?
use the imageTTFtext() function and concatenation the <br /> tag.
<?php
header(“Content-type: image/gif”);
$string = 'This is another text i want to include';
$im = imagecreate( 400, 200 );
$red = imagecolorallocate($image, 255,0,0);
$blue = imagecolorallocate($image, 0,0,255 );
$font = “/usr/local/jdk121_pre-v1/jre/lib/fonts/LucidaSansRegular.ttf”;
imageTTFtext( $im, 50, 0, 20, 100, $blue, $font, “This is some text!” );
imagegif($im);
?>
I created a canvas with a width of 400 pixels, you'll need a FreeType font in addition to your GD library. with the imageTTFtext() function i defined a width of 50 and angle of 0 of the text. so to make the string more complex, you can place the <br /> tag like this:
imageTTFtext( $im, 50, 0, 20, 100, $blue, $font, “This is some text!<br/>”.$string."some other text" );
Hope you get the picture now...
Related
im trying to make a form with php and gd library.
form contains a png logo with transparent packgroung.
now i have 3 problems:
when i make a border then i want to place the logo in top corner of
image, its not transparented background anymore
im using persian font and using imagettftext function. it show the
characters but in persian we have merged words but it show
characters seperated
how can i draw rounded corner borders
here is my code:
$fontSize=4;
$width = imagefontwidth($font) * strlen($string)+10 ;
$height = imagefontheight($font) ;
$handle = ImageCreate (800, 400) or die ("Cannot Create image");
$logo = imagecreatefrompng( 'Logo.png' );
$bg_color = ImageColorAllocate ($handle, 255, 240, 250);
$txt_color = ImageColorAllocate ($handle, 0, 0, 0);
$title="فرم قرارداد";
$font = "IRANSans.ttf";
$title_size = 18;
imagettftext( $handle, $title_size, 0, 620, 100, $txt_color, $font, $title );
$black = imagecolorallocate($handle, 0, 0, 0);
imagerectangle($handle, 20, 20, 780, 380, $black);
imagecopy($handle, $logo, 10, 10, 0, 0, 161, 160);
header('Content-Type: image/png');
imagepng($handle);
See this answer: php GD create a transparent png image
You'll have to use an OpenType (.otf) font, if you want to make use of your language's typographic characteristics.
You might want to take a look at GD's imagearc.
I'm having issues with text lining up where it should. Every tutorial I can find tells me to use imagettfbox to find the dimensions of the text. I do this, but the text doesn't fit within those dimensions.
See the example below:
<?php
// Create image and colours
$im = imagecreatetruecolor(200, 100);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
$red = imagecolorallocate($im, 255, 0, 0);
//Set the background to be white
imagefilledrectangle($im, 0, 0, 200, 100, $white);
//font file
$font = "ARIAL.TTF";
//set sample text and fontsize
$text="102";
$size = 25;
//calculate height and width of text1
$bbox = imagettfbbox($size, 0, $font, $text);
$width = $bbox[2] - $bbox[0];
$height = $bbox[5] - $bbox[3];
//draw rectangle that should house the text
imagefilledrectangle($im, 50, 40, 50+$width, 40+$height, $red);
//draw text at same startpoint as rectangle
imagettftext($im, $size, 0, 50, 40, $black, $font, $text);
// Output to browser
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
This should output a red rectangle, containing the text. It doesn't - the text is slightly to the right of where it should be. This only happens with some strings - ones that contain a "1" tend not to work, while some others work perfectly. Here is the output for 2 strings:
Does anyone know what is happening, and what I need to do to make the text fit correctly within the bounding box? I've tested this with multiple fonts, including monospace fonts - the same thing always happens.
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.
Please take look the demo site at
http://jsfiddle.net/Alidad/fexGj/
That demo is called "Image title", my next step is to convert both text and images as one group to images so that way i can click right mouse to copy and paste over.
However, there is PHP code that allow me to convert into the image from text but I can't hardly figure out how can I convert from "image title" (demo) into the HTML!
Here is sample PHP code but I can't figure out how to combine it!
<?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);
?>
Have any help me please how to convert this to images from jQuery code!
AM
Easiest way would probably be to just do:
// index.html
<img src="render_image.php?text=Hello World" />
and then:
// render_image.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, $_GET['text'], $textcolor);
// Output the image
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
Using this with slight modifications to your javascript code should work.
More info on using the $_GET variable: http://php.net/manual/en/reserved.variables.get.php
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);