memo.xight.org

01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

2007-01-29 Mon

PHPで画像にWatermark 加工

- Summary
二つの画像を合成し,Watermark加工が行なえる.

- Source

function emboss($pic1,$patt) {
	header("Content-type: image/png");
	
	$source=imagecreatefromjpeg($pic1);    // Source
	$pattern=imagecreatefromjpeg($patt);    // pattern
	list($width, $height) = getimagesize($pic1);
	list($widthpatt, $heightpatt) = getimagesize($patt);
	$new_width=$width;
	$new_height=$width/$widthpatt*$heightpatt;
	if($new_height>$height){
		$offset=intval(($new_height-$height)/2);
	}
	elseif($new_height<$height){
		$offset=intval(($new_height-$height)/2);
	}
	else{
		$offset=0;
	}
	
	$image_p = imagecreatetruecolor($new_width, $new_height);
	$pattern = imagecreatefromjpeg($patt);
	imagecopyresampled($image_p, $pattern, 0, 0, 0, 0, $new_width, $new_height, $widthpatt, $heightpatt);
	
	$im = imagecreatetruecolor($width, $height);   
	
	for($y=0; $y < $height; $y++) {
		for($x=0; $x < $width; $x++) {
			$colors=imagecolorsforindex($source, imagecolorat($source, $x,$y));
			$pattern_color=imagecolorsforindex($image_p, imagecolorat($image_p, $x,($y+$offset)));
			//changes brightness depending on luminance
			if(($y+$offset+1)>0 &&($y+$offset)<($new_height-1)){
				$brightness=abs(($pattern_color['red']*50/255)-50);
				if($pattern_color['red']<150){
					$change=true;}
				else{
					$change=false;
					$tally=0;
				}
				if($change&&$tally<2){
					$highlight=1.8;
					$tally++;
				}
				else{
					$highlight=1;
				}
				$brightness = $brightness * $highlight;
			}
			else{
				$brightness=0;
			}
			$r=(($colors['red']+$brightness)>255)? 255 : ($colors['red']+$brightness);
			$g=(($colors['green']+$brightness)>255)? 255 : ($colors['green']+$brightness);
			$b=(($colors['blue']+$brightness)>255)? 255 : ($colors['blue']+$brightness);
			
			$test=imagecolorallocate($im, $r,$g,$b);
			imagesetpixel($im,$x, $y, $test);
		}
	}
	imagepng($im);
	imagedestroy($im);
}
emboss("me.jpg","patternsq.jpg");
//emboss("magic800.jpg","patternsq.jpg");
//emboss("crop.jpg","patternsq.jpg");


<img src="emboss.php" />


- Reference
http://www.ckdog.co.uk/php/imgtests/emboss.phps

Watermarking JPEG and PNG Images with PHP and GD2
http://koivi.com/php-gd-image-watermark/

- via
Merge images / add logo - PHP
http://www.thescripts.com/forum/thread121386.html

カテゴリ: [PHP]
2007-01 / 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Color Reference

ChangeLogを検索
携帯電話からアクセス!

カテゴリ

最近の話題

リンク

過去ログ

Google

QR Code

Since
2002-11-28
Update
2008-02-20 21:23
Copyright © 2005 xight.org All Rights Reserved.