Page 1 of 2

fading strip for images

Posted: Sat Jun 03, 2006 2:39 am
by phpmash
I need a fading strip(black to transparent) to merge with the images uploaded to my site.
In which the user's name will be on the black side in white letters & the rest of the strip has to become transaprent to view the picture.
It wil be merged with the original image(jpeg,png,gif).

Can any one help me? :roll:

phpmash

Posted: Sat Jun 03, 2006 6:33 am
by bokehman
Sounds interesting... Can you create the image in photoshop/GIMP and post it somewhere?

Picture for work

Posted: Tue Jun 06, 2006 9:14 am
by phpmash
Thanks for response.Here i have uploaded a pic
You add a strip in the bottom side with a text "cloning is great" (Right aligned).
The area where the text comes will be black and the rest of the strip wants to become transparent(to left side..)

http://www.upithere.com/view/1119.html

phpmash

Re: Picture for work

Posted: Tue Jun 06, 2006 9:22 am
by bokehman
phpmash wrote:Thanks for response.Here i have uploaded a pic
You add a strip in the bottom side with a text "cloning is great" (Right aligned).
The area where the text comes will be black and the rest of the strip wants to become transparent(to left side..)

http://www.upithere.com/view/1119.html

phpmash
What I want you to do is post an image where you have added the mark that you are requesting. Once I see that image I will know if it is possible to do with GD.

Posted: Tue Jun 06, 2006 9:25 am
by onion2k
Like this?
Image

Posted: Tue Jun 06, 2006 9:56 am
by bokehman
onion2k wrote:Like this?
Image
My guess is that if it is like that it will only be possible with true color images.

Posted: Tue Jun 06, 2006 5:45 pm
by daedalus__
Onion, I love that picture you drew.

Exactly Correct

Posted: Wed Jun 07, 2006 9:16 am
by phpmash
HEllo
Exactly correct.I apprecite your imagination ability.
I want to do the same with jpeg,png,gif files....
I expect the code
Thanking you

phpmash

Re: Exactly Correct

Posted: Wed Jun 07, 2006 9:46 am
by bokehman
phpmash wrote:I expect the code
Blimey!

Posted: Wed Jun 07, 2006 10:03 am
by litebearer
The check is in the (e)mail.

Posted: Wed Jun 07, 2006 2:25 pm
by bokehman
Here is one possible way...

Image

Code: Select all

function SpeedStripWatermark($image, $text = NULL, $destination = NULL)
{
	# customisation section
	$corner = 3;   # distance from bottom right corner diagonally. value in pixels.
	$padding = 3;  # padding between text and text background in pixels
	$font = 5;     # 1 thru 5
	$textcolor = array('red' => 255, 'green' => 255, 'blue' => 255); # 0 thru 255
	$transColor = array('red' => 0, 'green' => 0, 'blue' => 0);      # 0 thru 255
	$quality = 75;   # for Jpegs: 0 = worst, 100 = best
	$text = ($text) ? $text : $_SERVER['HTTP_HOST'];
	$fade_rate = 0.975; # float: 0 thru 1
    	
	# now lets build the image
	$details = @getimagesize($image) or die("I cannot open $image");
	$type = preg_replace('@^.+(?<=/)(.+)$@', '$1', $details['mime']);
	eval('$image = imagecreatefrom'.$type.'($image);');
	$imageHeight = $details[1];
	$imageWidth = $details[0];
	$textWidth = (strlen($text) * ImageFontWidth($font)) + ($padding * 2);
	$textHeight = ImageFontHeight($font) + ($padding / 2);
	$textcolor = imagecolorallocate($image, $textcolor['red'], $textcolor['green'], $textcolor['blue']);
	$transparancyColor = imagecolorallocate($image, $transColor['red'], 
		$transColor['green'], $transColor['blue']);
	imagefilledrectangle($image, ($x1 = round($imageWidth - $textWidth - $corner)), ($y1 = round($imageHeight - $textHeight - $corner)), 
		($x2 = round($imageWidth - $corner)), ($y2 = round($imageHeight - $corner)), $transparancyColor);
	$bar = imagecreatetruecolor(1, round($y2 - $y1));
	$transparancyColor = imagecolorallocate($bar, $transColor['red'], 
		$transColor['green'], $transColor['blue']);
	imagefilledrectangle($bar, 0, 0, round($y2 - $y1), 1, $transparancyColor);
	$pct = 100;
	while($x1)
	{
		imagecopymerge($image, $bar, $x1--, $y1, 0, 0, 1, ($y2 - $y1)+1, ($pct = $pct * $fade_rate));
	}
	imagestring($image, $font, ($imageWidth - $textWidth - $corner) + $padding + 2,
		($imageHeight - $textHeight - $corner) + ($padding / 4), $text, $textcolor);
	$destination or header('Content-Type: '.$details['mime']);
	eval('image'.$type.'($image'.(($type=='jpeg')?',$destination,$quality':($destination?',$destination':'')).');');
	imagedestroy($image);
	imagedestroy($bar);
	$destination or die;
}

Posted: Wed Jun 07, 2006 4:13 pm
by onion2k
Very nice.

Posted: Wed Jun 07, 2006 5:12 pm
by daedalus__
/agree

Posted: Wed Jun 07, 2006 6:34 pm
by bokehman
Thanks!

Thanks...

Posted: Thu Jun 08, 2006 1:02 pm
by phpmash
Thank you very much bokehman
You did a great job for me.
See You Later here itself
phpmash :D