化方爲圓

<?php

$arr = getimagesize('a.png');
//var_dump($arr);

$w = $arr[0];
$h = $arr[1];
$minc = min($w,$h) / 2;
$minl = min($w,$h) / sqrt(M_PI) ;

$img = imagecreatefrompng('a.png');
$im = imagecreatetruecolor($minl* 2, $minl* 2);


for($wi = 0;$wi<$minl* 2;$wi++){
	for($hi = 0;$hi<$minl* 2;$hi++){
		if(pow(($wi - $minl),2)+pow(($hi - $minl),2)<= pow($minl,2)){
			$l= sqrt(pow(($wi - $minl),2)+pow(($hi - $minl),2));//弦長
			$ll = $l /2 * sqrt(M_PI);//方長
			$lx =abs($wi - $minl);
			$ly = abs($hi - $minl);
			if($lx < $ly){
				if($hi > $minl){
					$y = $minc + $ll;
				}else{
					$y = $minc - $ll;
				}

				$xx = asin($lx/$l)/(M_PI /4) * $ll;
				if($wi > $minl){
					$x = $minc + $xx;
				}else{
					$x = $minc - $xx;
				}


			}elseif($ly < $lx){
				if($wi > $minl){
					$x = $minc + $ll;
				}else{
					$x = $minc - $ll;
				}

				$xx = asin($ly/$l)/M_PI *4 * $ll;
				if($hi > $minl){
					$y = $minc + $xx;
				}else{
					$y = $minc - $xx;
				}

			}else{
				if($wi > $minl){
					$x = $minc + $ll;
				}else{
					$x = $minc - $ll;
				}

				if($hi > $minl){
					$y = $minc + $ll;
				}else{
					$y = $minc - $ll;
				}
			}


			$xxx = $l / $minl;
			$yyx = ($wi - $minl) /2 * sqrt(M_PI) +$minc;
			$yyy = ($hi - $minl) /2 * sqrt(M_PI) +$minc;

			$x = $yyx + ($x - $yyx) * $xxx;
			$y = $yyy + ($y - $yyy) * $xxx;







			$rgb = imagecolorat($img, $x, $y);
			imagesetpixel ($im , $wi , $hi ,$rgb);
		}
	}
}
//$rgb = imagecolorat($img, 100, 100);

//imagesetpixel ($im , int $x , int $y ,$rgb);


imagepng($im,'b.png');
相關文章
相關標籤/搜索