colonelwog 1485 Modules Team
| Posté : 25-05-2010 07:38
quelqu'un peut il m'aider à mettre en forme ce meta à partir du php merci :
function UnsharpMask($img, $amount, $radius, $threshold)& nbsp; {
///////////////////////////////////////////////////////////////////////////// ///////////////////
////
//// & nbsp; Unsharp Mask for PHP -&n bsp;version 2.1.1
////
//// Unsharp mask algorithm by Tor stein Hønsi 2003-07.
//// & nbsp;thoensi_at_netcom_dot_no.
//// & nbsp; Please leave this notice.
////
///////////////////////////////////////////////////////////////////////////// //////////////////
// $img is an image that&nbs p;is already created within php using
// imgcreatetruecolor. No url! $i mg must be a truecolor image.
// Attempt to calibrate the parameters to Photoshop:
if ($amount > 500)   ; $amount = 500;
$amount = $amount * 0.016;
if ($radius > 50) $radius = 50;
$radius = $radius * 2;
if ($threshold > 255) &n bsp; $threshold = 255;
$radius = abs(round($radius)); & nbsp; // Only integers make sense.
if ($radius == 0) {
return $img; imaged estroy($img); break; }  ;
$w = imagesx($img); $h = ima gesy($img);
$imgCanvas = imagecreatetruecolor($w, $h);
$imgBlur = imagecreatetruecolor($w, $h );
// Gaussian blur matrix:
// &nb sp; &nbs p;
// 1 2& nbsp; 1
// 2 4& nbsp; 2
// 1 2& nbsp; 1
// &nb sp; &nbs p;
//////////////////////////////////////////////////&nb sp;
if (function_exists('imageconvolution')) {& nbsp;// PHP >= 5.1
$matr ix = array(
array ( 1, 2, 1 ),
array ( 2, 4, 2 ),
array ( 1, 2, 1 )
);
imagecopy ($imgBlur,&nbs p;$img, 0, 0, 0, 0, $w, $h);
imageconvolution($imgBlur,&nb sp;$matrix, 16, 0);
}
else {
// Move copies of the image& nbsp;around one pixel at the time and merge& nbsp;them with weight
// according to the matrix. The same matrix is simply repeated for highe r radii.
for ($i = 0;&n bsp;$i < $radius; $i++) {
image copy ($imgBlur, $img, 0, 0, 1, 0, $w -& nbsp;1, $h); // left
image copymerge ($imgBlur, $img, 1, 0, 0, 0, $w,&n bsp;$h, 50); // right
image copymerge ($imgBlur, $img, 0, 0, 0, 0, $w,&n bsp;$h, 50); // center
image copy ($imgCanvas, $imgBlur, 0, 0, 0, 0, $w,& nbsp;$h);
image copymerge ($imgBlur, $imgCanvas, 0, 0, 0, 1,  ;$w, $h - 1, 33.33333 ); // up
image copymerge ($imgBlur, $imgCanvas, 0, 1, 0, 0,  ;$w, $h, 25); // down
}
}
if($threshold>0){
// Calculate the&nb sp;difference between the blurred pixels and the& nbsp;original
// and set the pixels
for ($x = 0;&n bsp;$x < $w-1; $x++) { // ea ch row
for&n bsp;($y = 0; $y < $h; $y++) & nbsp;{ // each pixel
  ;
  ; $rgbOrig = ImageColorAt($img, $x, $y);&n bsp;
  ; $rOrig = (($rgbOrig >> 16) &a mp; 0xFF);
  ; $gOrig = (($rgbOrig >> 8) &am p; 0xFF);
  ; $bOrig = ($rgbOrig & 0xFF);
  ;
  ; $rgbBlur = ImageColorAt($imgBlur, $x, $y );
  ;
  ; $rBlur = (($rgbBlur >> 16) &a mp; 0xFF);
  ; $gBlur = (($rgbBlur >> 8) &am p; 0xFF);
  ; $bBlur = ($rgbBlur & 0xFF);
  ;
  ; // When the masked pixels differ&nb sp;less from the original
  ; // than the threshold specifies, th ey are set to their original value.
  ; $rNew = (abs($rOrig - $rBlur) >= $threshold)
  ; ? max(0, min(255, ($a mount * ($rOrig - $rBlur)) + $rOrig))
  ; : $rOrig;
  ; $gNew = (abs($gOrig - $gBlur) >= $threshold)
  ; ? max(0, min(255, ($a mount * ($gOrig - $gBlur)) + $gOrig))
  ; : $gOrig;
  ; $bNew = (abs($bOrig - $bBlur) >= $threshold)
  ; ? max(0, min(255, ($a mount * ($bOrig - $bBlur)) + $bOrig))
  ; : $bOrig;
  ;
  ;
  ;
  ; if (($rOrig != $rNew) || ($gOrig&nb sp;!= $gNew) || ($bOrig != $bNew)) {
  ; $pixCol  ;= ImageColorAllocate($img, $rNew, $gNew, $bNew);
  ; ImageSetPixe l($img, $x, $y, $pixCol);
  ; }
}&nbs p;
}
}
else{
for ($x = 0;&n bsp;$x < $w; $x++) { // each row
for&n bsp;($y = 0; $y < $h; $y++) & nbsp;{ // each pixel
  ; $rgbOrig = ImageColorAt($img, $x, $y);&n bsp;
  ; $rOrig = (($rgbOrig >> 16) &a mp; 0xFF);
  ; $gOrig = (($rgbOrig >> 8) &am p; 0xFF);
  ; $bOrig = ($rgbOrig & 0xFF);
  ;
  ; $rgbBlur = ImageColorAt($imgBlur, $x, $y );
  ;
  ; $rBlur = (($rgbBlur >> 16) &a mp; 0xFF);
  ; $gBlur = (($rgbBlur >> 8) &am p; 0xFF);
  ; $bBlur = ($rgbBlur & 0xFF);
  ;
  ; $rNew = ($amount * ($rOrig - $ rBlur)) + $rOrig;
  ; if($rNew>255){$rNew=255;}
< br />   ; elseif($rNew<0){$rNew=0;}
< br />   ; $gNew = ($amount * ($gOrig - $ gBlur)) + $gOrig;
  ; if($gNew>255){$gNew=255;}
< br />   ; elseif($gNew<0){$gNew=0;}
< br />   ; $bNew = ($amount * ($bOrig - $ bBlur)) + $bOrig;
  ; if($bNew>255){$bNew=255;}
< br />   ; elseif($bNew<0){$bNew=0;}
< br />   ; $rgbNew = ($rNew << 16) +&nbs p;($gNew <<8) + $bNew;
  ; ImageSetPixel($img, $x, $y , $rgbNew);
}&nbs p;
}
}
imagedestroy($imgCanvas);
imagedestroy($imgBlur);
return $img;
}
code source ici: http://vikjavev.no/computing/ump.php?id=350 |  Profil E-mail www |
|