Question

I have a watermark on to the image and i want to create its shadow using php GD.how can i calculate the distance that how far is the shadow and at what position if i have only the angle and distance from the watermark

for example
$shadowAngle = 90;// in radian 
$shadowDistance = 100// in % means 100 percent away from watermark

$watermark_x = 320;  //width of watermark
$watermark_y = 320;  //height of watermark

$watermark_Pointx = 640;  // x of watermark on background Image
$watermark_Pointy = 140; // y of watermark on background Image

$shadow_Pointx = ?  // x of shadow on background Image
$shadow_Pointy = ? // y of shadow on background Image

How can i calculate starting points of shadow($shadow_Pointx,$shadow_Pointy) by using $shadowAngle and $shadowdistance

enter image description here

Was it helpful?

Solution

How about this equation:

$shadow_Pointx = $watermark_Pointx + ($shadowDistance/100 * $watermark_x * sin($shadowAngle))

$shadow_Pointy = $watermark_Pointy + ($shadowDistance/100 * $watermark_y * cos($shadowAngle))

By assuming 90 degree will set the shadow on the right side of the watermark, I guess the result should be 960,140..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top