hovercraft
Technical User
Greetings,
I am using faq434-5838 by kb244 titled, "Applying Text to Image with transparency".
I uploaded the file = CENTURY.TTF for my font. It's in the same directory as my .php.
I'm trying to display some text over a graphic of a t-shirt. The image displays but not the text. I'm wondering if the font actually has to be installed on the server and not just simply uploaded. The site is hosted by a hosting company so I don't know if I can install fonts on their server (or if this even makes sense).
Here is the code.
Is there a problem with the code or is it the font?
Thanks in advance,
Hovercraft
I am using faq434-5838 by kb244 titled, "Applying Text to Image with transparency".
I uploaded the file = CENTURY.TTF for my font. It's in the same directory as my .php.
I'm trying to display some text over a graphic of a t-shirt. The image displays but not the text. I'm wondering if the font actually has to be installed on the server and not just simply uploaded. The site is hosted by a hosting company so I don't know if I can install fonts on their server (or if this even makes sense).
Here is the code.
Code:
<?php
Header ("Content-type: image/png");
//The copy of the image that will act as the bottom layer
$src_img = imagecreatefromjpeg('imgs/teebl.jpg');
//The copy of the image that will act as the transparent top layer
$cpy_img = imagecreatefromjpeg('imgs/teebl.jpg');
//stores the image's dimensions
$img_width = imagesx($src_img);
$img_height = imagesy($src_img);
//The color of the font you wish to draw 0 to 255 for each value to make a truecolor result
$red = 255;
$green = 0;
$blue = 0;
//allocates the font color based on the RGB value
$font_color = imagecolorallocate($src_img, $red, $green, $blue);
//Sets the font file, this can be just about any true type font you upload to the server
$font_file = "CENTURY.TTF";
//Sets the font size, based on point sizes, such as 8, 10, 14, 16, so on
$font_size = 28;
//Sets the angle of the font
$angle = 0;
//finds the boundary of the text box, this part is setup with the assumption of 0 degree angle
//an angle other than zero the next three lines may not be accurate
$textdimension = imagettfbbox($font_size,$angle, $font_file, "Karl Blessing Photography");
$textheight = $textdimension[3] - $textdimension[5];
$textwidth = $textdimension[2] - $textdimension[0];
$position = "center"; //choices are top, bottom, center
if (strcmp($position, "top") == 0)
$y_start = $textheight;
elseif (strcmp($position, "bottom") == 0)
$y_start = $new_h - ($textheight / 2);
else
$y_start = ($new_h / 2) - ($textheight / 2);
//Sets the horizontal starting position to allow for a horizontally centered text
$x_start = ($new_w - ($line_width[2] - $line_width[0])) / 2;
$transparency = 75; //set this reverse what you want, if you want 25% transparency on text, set this to 75
//applies the text onto the bottom layer
imagettftext($src_img, $font_size, $angle, $x_start, $y_start, $black, $font_file, "Karl Blessing Photography");
//merges the top copy over the altered bottom copy causing the illusion of transparent text
//imagecopymerge( $src_img, $cpy_img, 0 , 0 , 0, 0, $new_w, $new_h, $tran);
//Caches the image for later use so you dont hog the processor
imagejpeg($src_img,$wm_cache.$gallery."_".$file.".jpg", 80);
//Sends the new data back to the browser for viewing
imagejpeg($src_img,"",80);
//Clears the images from memory
imagedestroy($cpy_img);
imagedestroy($src_img);
?>
Is there a problem with the code or is it the font?
Thanks in advance,
Hovercraft