Karl Blessing
Programmer
I have the following code, what it basically does is take the standard method of writing text into an image, however because text methods ( that I know of ) , will not allow you to make a font color somewhat transparent, I am creating a blank image on the fly, filling the background, setting the background color transparent, writing the text onto that image, then doing a merge into the source image with the watermarked layer set to a degree of transparency, everything is fine except for one small nitpick, when looking at the text , the edges have the color of the background partly there, making it look like a very unclean crop out of a transparency, is there any way around this?
Code Below
And yes I'm aware of caching the image for later use and so on, I just want to get this working before I move onto that part.
Karl Blessing
PHP/MySQL Developer
Code Below
Code:
$src_img = imagecreatefromjpeg(---Path To Source Image---);
$new_w = imagesx($src_img);
$new_h = imagesy($src_img);
$wm = @imagecreate($new_w, $new_h)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($wm, 255, 255, 255);
$black = imagecolorallocate($wm, $red, $green, $blue);
$font_file = "/home/kb244/arial.ttf";
$font_size = 28;
$y_start = 200;
$angle = 0;
$max_width= 400;
$line_width = imagettfbbox($font_size,$angle, $font_file, "String Here");
$x_start = ($new_w - ($line_width[2] - $line_width[0])) / 2;
imagettftext($wm, $font_size, $angle, $x_start, $y_start, $black, $font_file, "String here");
imagecolortransparent($wm,$background_color) ;
imagecopymerge( $src_img, $wm, $new_w /50 , $new_h /50 , 0, 0, $new_w, $new_h, $tran);
imagepng($src_img);
imagedestroy($wm);
imagedestroy($src_img);
And yes I'm aware of caching the image for later use and so on, I just want to get this working before I move onto that part.
Karl Blessing
PHP/MySQL Developer