Jump to content

Add drop shadow


cheechm

Recommended Posts

Hi,

Could you help me add a drop shadow? I was told that if you create a new image that is grey and position it 3 pixels under the current one, then that would work. How could I do that? Also, I want to make an image that is only as big as the text. I was told something like imagettfbox or something. I don't know anything, so all help is appreciated.

 

Thanks

 

<?php
if($_GET['text'] == "")
{
die ("No text input");
}
else
{
$text = $_GET['text'];
}
$save_path = "F:/Server/ig/";
$rand = rand();
$image_name = $rand .'.png';
set_time_limit(0);
ini_set("memory_limit","100M");
//GET TYPE (THAT USER WANTS)
$type = @$_GET['type'];
if ($type == false)
{
    $type = 'top';
}

//GET DIMENTIONS (THAT USER WANTS)
$height = intval(@$_GET['height']);
if ($height == 0)
{
    $height = 800;
}
$width = intval(@$_GET['width']);
if ($width == 0)
{
    $width = 1600;
}

//GET HEX COLOURS (THAT USER WANTS)
$start_colour = $_GET['start_colour'];
if ($start_colour == false)
{
    $start_colour = '1d69cc';
}
$end_colour = $_GET['end_colour'];
if ($end_colour == false)
{
    $end_colour = '052349';
}

//CONVERT HEX COLOURS TO RGB
$hex_r = substr($start_colour, 0, 2);
$hex_g = substr($start_colour, 2, 2);
$hex_b = substr($start_colour, 4, 2);

$start_r = hexdec($hex_r);
$start_g = hexdec($hex_g);
$start_b = hexdec($hex_b);

$hex_r = substr($end_colour, 0, 2);
$hex_g = substr($end_colour, 2, 2);
$hex_b = substr($end_colour, 4, 2);

$end_r = hexdec($hex_r);
$end_g = hexdec($hex_g);
$end_b = hexdec($hex_b);

//CREATE BLANK IMAGE
$image = @imagecreatetruecolor($width, $height) or die("Cannot Initialize new GD image stream");
imagealphablending($image, true);
imagesavealpha($image, true);

if ($type == 'top')
{

    //LOOP THROUGH ALL THE PIXELS
    for ($y = 0; $y < $height; $y++)
    {

        //LOOP THROUGH ROW
        for ($x = 0; $x < $width; $x++)
        {

            //CALCULATE THIS ROWS RGB COLOURS

            if ($start_r == $end_r)
            {
                $new_r = $start_r;
            }
            $difference = $start_r - $end_r;
            $new_r = $start_r - intval(($difference / $height) * $y);

            //====

            if ($start_g == $end_g)
            {
                $new_g = $start_g;
            }
            $difference = $start_g - $end_g;
            $new_g = $start_g - intval(($difference / $height) * $y);

            //===

            if ($start_b == $end_b)
            {
                $new_b = $start_b;
            }
            $difference = $start_b - $end_b;
            $new_b = $start_b - intval(($difference / $height) * $y);

            //===

            //ALLOCATE THE COLOR
            $row_color = imagecolorresolve($image, $new_r, $new_g, $new_b);

            //CREATE ROW OF THIS COLOR
            imagesetpixel($image, $x, $y, $row_color);

        }

    }

}

if ($type == 'left')
{

    //LOOP THROUGH ALL THE PIXELS
    for ($x = 0; $x < $width; $x++)
    {

        //LOOP THROUGH COLUMN
        for ($y = 0; $y < $height; $y++)
        {

            //CALCULATE THIS ROWS RGB COLOURS

            if ($start_r == $end_r)
            {
                $new_r = $start_r;
            }
            $difference = $start_r - $end_r;
            $new_r = $start_r - intval(($difference / $width) * $x);

            //====

            if ($start_g == $end_g)
            {
                $new_g = $start_g;
            }
            $difference = $start_g - $end_g;
            $new_g = $start_g - intval(($difference / $width) * $x);

            //===

            if ($start_b == $end_b)
            {
                $new_b = $start_b;
            }
            $difference = $start_b - $end_b;
            $new_b = $start_b - intval(($difference / $width) * $x);

            //===

            //ALLOCATE THE COLOR
            $row_color = imagecolorresolve($image, $new_r, $new_g, $new_b);

            //CREATE ROW OF THIS COLOR
            imagesetpixel($image, $x, $y, $row_color);

        }

    }

}

$bgcol = imagecolorallocate($image, 255, 255, 255);
$mask = imagecreate($width, $height); // mask image
imagealphablending($mask, true);
imagesavealpha($mask, true);
$maskbg = imagecolorallocate($mask, 255, 255, 255);
$masktextcol = imagecolorallocate($mask, 0, 0, 0);
imagettftext($mask, 499, 0, 10, 500, $masktextcol,
    'C:/windows/fonts/calibri.ttf', $text);


for ($x = 0; $x < $width; $x++)
{
    for ($y = 0; $y < $height; $y++)
    {
        if (imagecolorat($mask, $x, $y) == $maskbg)
        {
            imagesetpixel($image, $x, $y, $bgcol);
        }
    }
}
$small = imagecreatetruecolor(200, 100);
imagealphablending($small, true);
imagesavealpha($small, true);
imagecopyresampled($small, $image, 0, 0, 0, 0, 200, 100, $width, $height);

$tc = imagecolorat($small, 0, 0);
imagecolortransparent($small, $tc);
imagetruecolortopalette($small, true, 256);


// no need for header
imagepng($small, $save_path . $image_name); // this will save the file rather than display it
imagedestroy($mask);
imagedestroy($image);
imagedestroy($small);
// run sql below to save image name

$con = mysql_connect("localhost", "root", "DUMBASS1");
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}


mysql_select_db("qw", $con);
$sql = "INSERT INTO images (`id`, `image_name`) VALUES ('$rand', '$image_name')";
$result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
if($result)
{
echo "Everything Successful! <br />Image is called ". $image_name ." and the id is" .$rand. "
<br />To use, use this code: <xmp><img src=\"". $image_name ."\" /></xmp>";

}

?>

Link to comment
https://forums.phpfreaks.com/topic/105449-add-drop-shadow/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.