fading strip for images

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
phpmash
Forum Newbie
Posts: 24
Joined: Mon Oct 31, 2005 6:41 am
Location: Kerala,India
Contact:

fading strip for images

Post 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
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

Sounds interesting... Can you create the image in photoshop/GIMP and post it somewhere?
User avatar
phpmash
Forum Newbie
Posts: 24
Joined: Mon Oct 31, 2005 6:41 am
Location: Kerala,India
Contact:

Picture for work

Post 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
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Re: Picture for work

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Like this?
Image
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

Onion, I love that picture you drew.
User avatar
phpmash
Forum Newbie
Posts: 24
Joined: Mon Oct 31, 2005 6:41 am
Location: Kerala,India
Contact:

Exactly Correct

Post 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
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Re: Exactly Correct

Post by bokehman »

phpmash wrote:I expect the code
Blimey!
litebearer
Forum Contributor
Posts: 194
Joined: Sat Mar 27, 2004 5:54 am

Post by litebearer »

The check is in the (e)mail.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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;
}
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Very nice.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

/agree
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

Thanks!
User avatar
phpmash
Forum Newbie
Posts: 24
Joined: Mon Oct 31, 2005 6:41 am
Location: Kerala,India
Contact:

Thanks...

Post by phpmash »

Thank you very much bokehman
You did a great job for me.
See You Later here itself
phpmash :D
Post Reply