Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Using GD to add text over image with drop shadow blur

Avatar of ray-solomon
ray-solomonFlag for United States of America asked on
PHP
12 Comments1 Solution8198 ViewsLast Modified:
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);

?>
image.png