Avatar of ray-solomon
ray-solomon
Flag for United States of America

asked on 

Using GD to add text over image with drop shadow blur

I have a 24-bit png file that I need to overlay a text with a drop shadow.
The drop shadow is a copy of the text with an offset and Gaussian blur.

I need help getting this to work.

I attached an example image and existing code.
<?php

/* 24-bit PNG source image */
$src_image = 'image.png';

/* create new image from source image */
$im_base = @imagecreatefrompng($src_image);
$width = imagesx($im_base);
$height = imagesy($im_base);

/*
$drop_shadow = imagecreatetruecolor($width, $height);

$black = imagecolorallocate($drop_shadow, 0, 0, 0);
imagecolortransparent($drop_shadow, $black);
*/

/* 
$transparent = imagecolorallocatealpha($img, 0,0,0, 127); 
*/

/* alpha blending on 
imagealphablending($drop_shadow, true);*/

/* save alphablending setting 
imagesavealpha($drop_shadow, false); */



/* drop shadow text 
$font = 'Banty.ttf';
$fontSize = 70; // points
$fontRotation = 0; //  0 degrees
$fontX = -5; // pixels
$fontY = 75; // pixels
$fontColor = imagecolorallocate($drop_shadow, 0xD6, 0xD6, 0xD6); // hex or RGB
$text = "Test";
*/

/* add text to image 
imagettftext($drop_shadow, $fontSize, $fontRotation, $fontX, $fontY, $fontColor, $font, $text);
*/

/* add blur shadow 
imagefilter($drop_shadow, IMG_FILTER_GAUSSIAN_BLUR);
imagefilter($drop_shadow, IMG_FILTER_GAUSSIAN_BLUR);
imagefilter($drop_shadow, IMG_FILTER_GAUSSIAN_BLUR);
*/

/*
imagecopymerge($im, $drop_shadow, 50, 50, 50, 50, $width, $height, 100);
imagecopyresampled($im, $drop_shadow, 0, 0, 0, 0, $width, $height, $width, $height);
*/

/* customize the text 
$font = 'Banty.ttf';
$fontSize = 70; // points
$fontRotation = 0; //  0 degrees
$fontX = 1; // pixels
$fontY = 70; // pixels
$color = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); // hex or RGB
$text = "Test";
*/

/* add text to image 
@imagettftext($im_base, $fontSize, $fontRotation, $fontX, $fontY, $color, $font, $text);
*/


/* output image */
header('Content-type: image/png');
@imagepng($im_base);
/* empty the buffer */
@imagedestroy($im_base);

?>

Open in new window

image.png
PHP

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon