shadows in gd image

Started on the old forum in December 2010 · view the original in the archive · old links redirect here

6 replies · 434 views · started 15 years ago · 1 min read

3 participants
ori Lead · 512 posts #1

im trying to add a shadow to my image generator it generates png transparent bg by telling it font color, font size and text.

i dunno how to add shadow to the image

External image (may be gone)

Added after 56 minutes:

just realised it may help if i post my code

<?php
header("Content-type: image/png"); //Picture Format 
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 
header("Pragma: no-cache"); // NO CACHE 
$size = imagettfbbox($_GET['size'], 0, $font,$_GET['text']);
$bg = imagecreatetruecolor($xsize, $ysize); //create Image of size 350px x 75px 
imagesavealpha($bg, true); //This will make it transparent 
$trans_colour = imagecolorallocatealpha($bg, 0, 0, 0, 127); 
imagefill($bg, 0, 0, $trans_colour); 
$color = ImageColorAllocate($bg,$r_txt,$g_txt,$b_txt);
imagettftext($bg, $_GET['size'], 0, abs($size[0]), abs($size[5]), $color, $font, $_GET['text']); //Writes text to the image using fonts using FreeType 2 
imagepng($bg); //Create image 
ImageDestroy($bg); //destroy image 
?>
Anshul Senior · 296 posts #2

you may use ImageMagick it wil more easier fr u to achieve the same 🙂

ori Lead · 512 posts #4

i know i wasnt gonna give away my code lol... it has bits missing but u can access the file here: wapdesire.com/img.php?color=ff0000&text=test&size=50

Anshul wrote: you may use ImageMagick it wil more easier fr u to achieve the same :)

i would if i knew it theres no point trying to use something i know nothing about...

ori Lead · 512 posts #5

problem fixed the solution was quite easy

$black = imagecolorallocate($bg, 0,0,0);
$color = ImageColorAllocate($bg,$r_txt,$g_txt,$b_txt);
$xoffset = abs($size[0])/8;
$yoffset = abs($size[5])/8;
imagettftext($bg, $_GET['size'], 0, abs($size[0])+$xoffset, abs($size[5])+$yoffset, $black, $font, $_GET['text']); //Writes text to the image using fonts using FreeType 2 
imagettftext($bg, $_GET['size'], 0, abs($size[0]), abs($size[5]), $color, $font, $_GET['text']); //Writes text to the image using fonts using FreeType 2 
imagepng($bg); //Create image 
ImageDestroy($bg); //destroy image 
ori Lead · 512 posts #7

ok thanks ill have a look

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close