Avatar billede kaktus Nybegynder
13. juli 2008 - 17:36 Der er 15 kommentarer og
1 løsning

UnsharpMask i php

Hvordan er det lige jeg får dette til at virke.........<UnsharpMask>til brug ved jpg billeder på www.

Jeg kunne både tænke mig en demo side som http://vikjavev.no/computing/ump.php?id=254 (med submit form), så jeg lærer lidt ved det og en måde at "gøre tingene" on the fly i mit upload script som bruger denne funktion.

<? function skaler_jpg($img,$w,$h) {
$thumbnail = imagecreatetruecolor ($w, $h);
$billede = ImageCreateFromJpeg($img);
$billedstr = getimagesize($img);
imagecopyresized ($thumbnail, $billede, 0, 0, 0, 0, $w, $h, $billedstr[0], $billedstr[1]);
imagejpeg($thumbnail,$img,$jpegqual);
}?>

Men i første omgang har jeg forsøgt mig med dette som giver fejl....
$img="thmb_ny50.jpg";
$amount=80;//(typically 50 - 200)
$radius=0.5;//(typically 0.5 - 1)
$threshold=3;//(typically 0 - 5)
$final= applyUnsharpMask($img, $amount, $radius, $threshold);
echo $final;

Fatal error: Call to undefined function applyUnsharpMask()
Avatar billede jakobdo Ekspert
13. juli 2008 - 18:40 #1
Det er vel fordi du mangler funktionen: applyUnsharpMask() ?
Avatar billede kaktus Nybegynder
13. juli 2008 - 19:21 #2
Det bliver vist mest overskueligt hvis min samlede koder kommer her.............

<?php
//////////////////////////////////////////////////////////////
////                                                      ////
////              p h p U n s h a r p M a s k            ////
////                                                      ////
////    Unsharp mask algorithm by Torstein Hønsi 2003.    ////
////              thoensi_at_netcom_dot_no              ////
////              Please leave this notice.              ////
////                                                      ////
//////////////////////////////////////////////////////////////
/// From: http://vikjavev.no/hovudsida/umtestside.php      //
//                                                          //
//  Reformatted by James Heinrich <info@silisoftware.com>  //
//  for use in phpThumb() on 3 February 2003.              //
//                                                          //
//  phpThumb() is found at http://phpthumb.sourceforge.net ///
//////////////////////////////////////////////////////////////

/*
WARNING! Due to a known bug in PHP 4.3.2 this script is not working well in this version.
The sharpened images get too dark. The bug is fixed in version 4.3.3.

Unsharp masking is a traditional darkroom technique that has proven very suitable for
digital imaging. The principle of unsharp masking is to create a blurred copy of the image
and compare it to the underlying original. The difference in colour values
between the two images is greatest for the pixels near sharp edges. When this
difference is subtracted from the original image, the edges will be
accentuated.

The Amount parameter simply says how much of the effect you want. 100 is 'normal'.
Radius is the radius of the blurring circle of the mask. 'Threshold' is the least
difference in colour values that is allowed between the original and the mask. In practice
this means that low-contrast areas of the picture are left unrendered whereas edges
are treated normally. This is good for pictures of e.g. skin or blue skies.

Any suggenstions for improvement of the algorithm, expecially regarding the speed
and the roundoff errors in the Gaussian blur process, are welcome.
*/

class phpUnsharpMask {

    function applyUnsharpMask($img, $amount, $radius, $threshold) {

        // $img is an image that is already created within php using
        // imgcreatetruecolor. No url! $img must be a truecolor image.

        // Attempt to calibrate the parameters to Photoshop:
        $amount = min($amount, 500);
        $amount = $amount * 0.016;
        if ($amount == 0) {
            return true;
        }

        $radius = min($radius, 50);
        $radius = $radius * 2;

        $threshold = min($threshold, 255);

        $radius = abs(round($radius));    // Only integers make sense.
        if ($radius == 0) {
            return true;
        }

        $w = ImageSX($img);
        $h = ImageSY($img);
        $imgCanvas  = ImageCreateTrueColor($w, $h);
        $imgCanvas2 = ImageCreateTrueColor($w, $h);
        ImageCopy($imgCanvas,  $img, 0, 0, 0, 0, $w, $h);
        ImageCopy($imgCanvas2, $img, 0, 0, 0, 0, $w, $h);


        $builtinFilterSucceeded = false;
        if ($radius == 1) {
            if (phpthumb_functions::version_compare_replacement(phpversion(), '5.0.0', '>=') && phpthumb_functions::gd_is_bundled()) {
                if (ImageFilter($imgCanvas, IMG_FILTER_GAUSSIAN_BLUR) && ImageFilter($imgCanvas2, IMG_FILTER_GAUSSIAN_BLUR)) {
                    $builtinFilterSucceeded = true;
                }
            }
        }

        if (!$builtinFilterSucceeded) {
            $imgBlur  = ImageCreateTrueColor($w, $h);
            $imgBlur2 = ImageCreateTrueColor($w, $h);

            ///////////////////////////
            //
            // Gaussian blur matrix:
            //    1  2  1
            //    2  4  2
            //    1  2  1
            //
            ///////////////////////////

            // Move copies of the image around one pixel at the time and merge them with weight
            // according to the matrix. The same matrix is simply repeated for higher radii.
            for ($i = 0; $i < $radius; $i++)    {
                ImageCopy    ($imgBlur, $imgCanvas, 0, 0, 1, 1, $w - 1, $h - 1);            // up left
                ImageCopyMerge($imgBlur, $imgCanvas, 1, 1, 0, 0, $w,    $h,    50);        // down right
                ImageCopyMerge($imgBlur, $imgCanvas, 0, 1, 1, 0, $w - 1, $h,    33.33333);  // down left
                ImageCopyMerge($imgBlur, $imgCanvas, 1, 0, 0, 1, $w,    $h - 1, 25);        // up right
                ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 1, 0, $w - 1, $h,    33.33333);  // left
                ImageCopyMerge($imgBlur, $imgCanvas, 1, 0, 0, 0, $w,    $h,    25);        // right
                ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 0, 1, $w,    $h - 1, 20 );      // up
                ImageCopyMerge($imgBlur, $imgCanvas, 0, 1, 0, 0, $w,    $h,    16.666667); // down
                ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 0, 0, $w,    $h,    50);        // center
                ImageCopy    ($imgCanvas, $imgBlur, 0, 0, 0, 0, $w,    $h);

                // During the loop above the blurred copy darkens, possibly due to a roundoff
                // error. Therefore the sharp picture has to go through the same loop to
                // produce a similar image for comparison. This is not a good thing, as processing
                // time increases heavily.
                ImageCopy    ($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h);
                ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50);
                ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333);
                ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25);
                ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333);
                ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25);
                ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 20 );
                ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 16.666667);
                ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50);
                ImageCopy    ($imgCanvas2, $imgBlur2, 0, 0, 0, 0, $w, $h);
            }
            ImageDestroy($imgBlur);
            ImageDestroy($imgBlur2);
        }

        // Calculate the difference between the blurred pixels and the original
        // and set the pixels
        for ($x = 0; $x < $w; $x++)    { // each row
            for ($y = 0; $y < $h; $y++)    { // each pixel

                $rgbOrig = ImageColorAt($imgCanvas2, $x, $y);
                $rOrig = (($rgbOrig >> 16) & 0xFF);
                $gOrig = (($rgbOrig >>  8) & 0xFF);
                $bOrig =  ($rgbOrig        & 0xFF);

                $rgbBlur = ImageColorAt($imgCanvas, $x, $y);
                $rBlur = (($rgbBlur >> 16) & 0xFF);
                $gBlur = (($rgbBlur >>  8) & 0xFF);
                $bBlur =  ($rgbBlur        & 0xFF);

                // When the masked pixels differ less from the original
                // than the threshold specifies, they are set to their original value.
                $rNew = (abs($rOrig - $rBlur) >= $threshold) ? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig)) : $rOrig;
                $gNew = (abs($gOrig - $gBlur) >= $threshold) ? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig)) : $gOrig;
                $bNew = (abs($bOrig - $bBlur) >= $threshold) ? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig)) : $bOrig;

                if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew)) {
                    $pixCol = ImageColorAllocate($img, $rNew, $gNew, $bNew);
                    ImageSetPixel($img, $x, $y, $pixCol);
                }
            }
        }
        ImageDestroy($imgCanvas);
        ImageDestroy($imgCanvas2);

        return true;
    }

}

$img="thmb_ny50.jpg";
$amount=80;//(typically 50 - 200)
$radius=0.5;//(typically 0.5 - 1)
$threshold=3;//(typically 0 - 5)
$final= applyUnsharpMask($img, $amount, $radius, $threshold);
echo $final;
?>
Avatar billede jakobdo Ekspert
13. juli 2008 - 21:02 #3
Der står også du skal bruge: http://phpthumb.sourceforge.net
Har du hentet det ?
Avatar billede coderdk Praktikant
13. juli 2008 - 21:42 #4
applyUnsharpMask skal vel være phpUnsharpMask::applyUnsharpMask - ellers skal du instantiere phpUnsharpMask og kalde applyUnsharpMask via objektet ;)
Avatar billede kaktus Nybegynder
13. juli 2008 - 22:32 #5
coderdk......
mener du sådan...
$final= phpUnsharpMask::applyUnsharpMask($img, $amount, $radius, $threshold);
echo $final;

giver dette resultat
http://testkalender.sluk.dk/img/UnsharpMask.php

MEN er ikke interesseret i at bruge http://phpthumb.sourceforge.net
og kunne ligeså godt bruge denne
http://vikjavev.no/computing/ump.php?id=254
som er den jeg helst vil bruge...
kommer her
<?php

/*

New:
- In version 2.1 (February 26 2007) Tom Bishop has done some important speed enhancements.
- From version 2 (July 17 2006) the script uses the imageconvolution function in PHP
version >= 5.1, which improves the performance considerably.


Unsharp masking is a traditional darkroom technique that has proven very suitable for
digital imaging. The principle of unsharp masking is to create a blurred copy of the image
and compare it to the underlying original. The difference in colour values
between the two images is greatest for the pixels near sharp edges. When this
difference is subtracted from the original image, the edges will be
accentuated.

The Amount parameter simply says how much of the effect you want. 100 is 'normal'.
Radius is the radius of the blurring circle of the mask. 'Threshold' is the least
difference in colour values that is allowed between the original and the mask. In practice
this means that low-contrast areas of the picture are left unrendered whereas edges
are treated normally. This is good for pictures of e.g. skin or blue skies.

Any suggenstions for improvement of the algorithm, expecially regarding the speed
and the roundoff errors in the Gaussian blur process, are welcome.

*/

function UnsharpMask($img, $amount, $radius, $threshold)    {

//////////////////////////////////////////////////////////////////////////////////////////////// 
//// 
////                  Unsharp Mask for PHP - version 2.1.1 
//// 
////    Unsharp mask algorithm by Torstein Hønsi 2003-07. 
////            thoensi_at_netcom_dot_no. 
////              Please leave this notice. 
//// 
/////////////////////////////////////////////////////////////////////////////////////////////// 



    // $img is an image that is already created within php using
    // imgcreatetruecolor. No url! $img 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)    $threshold = 255;
   
    $radius = abs(round($radius));    // Only integers make sense.
    if ($radius == 0) {
        return $img; imagedestroy($img); break;        }
    $w = imagesx($img); $h = imagesy($img);
    $imgCanvas = imagecreatetruecolor($w, $h);
    $imgBlur = imagecreatetruecolor($w, $h);
   

    // Gaussian blur matrix:
    //                       
    //    1    2    1       
    //    2    4    2       
    //    1    2    1       
    //                       
    //////////////////////////////////////////////////
       

    if (function_exists('imageconvolution')) { // PHP >= 5.1 
            $matrix = array( 
            array( 1, 2, 1 ), 
            array( 2, 4, 2 ), 
            array( 1, 2, 1 ) 
        ); 
        imagecopy ($imgBlur, $img, 0, 0, 0, 0, $w, $h);
        imageconvolution($imgBlur, $matrix, 16, 0); 
    } 
    else { 

    // Move copies of the image around one pixel at the time and merge them with weight
    // according to the matrix. The same matrix is simply repeated for higher radii.
        for ($i = 0; $i < $radius; $i++)    {
            imagecopy ($imgBlur, $img, 0, 0, 1, 0, $w - 1, $h); // left
            imagecopymerge ($imgBlur, $img, 1, 0, 0, 0, $w, $h, 50); // right
            imagecopymerge ($imgBlur, $img, 0, 0, 0, 0, $w, $h, 50); // center
            imagecopy ($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h);

            imagecopymerge ($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 33.33333 ); // up
            imagecopymerge ($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 25); // down
        }
    }

    if($threshold>0){
        // Calculate the difference between the blurred pixels and the original
        // and set the pixels
        for ($x = 0; $x < $w-1; $x++)    { // each row
            for ($y = 0; $y < $h; $y++)    { // each pixel
                   
                $rgbOrig = ImageColorAt($img, $x, $y);
                $rOrig = (($rgbOrig >> 16) & 0xFF);
                $gOrig = (($rgbOrig >> 8) & 0xFF);
                $bOrig = ($rgbOrig & 0xFF);
               
                $rgbBlur = ImageColorAt($imgBlur, $x, $y);
               
                $rBlur = (($rgbBlur >> 16) & 0xFF);
                $gBlur = (($rgbBlur >> 8) & 0xFF);
                $bBlur = ($rgbBlur & 0xFF);
               
                // When the masked pixels differ less from the original
                // than the threshold specifies, they are set to their original value.
                $rNew = (abs($rOrig - $rBlur) >= $threshold) 
                    ? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig)) 
                    : $rOrig;
                $gNew = (abs($gOrig - $gBlur) >= $threshold) 
                    ? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig)) 
                    : $gOrig;
                $bNew = (abs($bOrig - $bBlur) >= $threshold) 
                    ? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig)) 
                    : $bOrig;
               
               
                           
                if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew)) {
                        $pixCol = ImageColorAllocate($img, $rNew, $gNew, $bNew);
                        ImageSetPixel($img, $x, $y, $pixCol);
                    }
            }
        }
    }
    else{
        for ($x = 0; $x < $w; $x++)    { // each row
            for ($y = 0; $y < $h; $y++)    { // each pixel
                $rgbOrig = ImageColorAt($img, $x, $y);
                $rOrig = (($rgbOrig >> 16) & 0xFF);
                $gOrig = (($rgbOrig >> 8) & 0xFF);
                $bOrig = ($rgbOrig & 0xFF);
               
                $rgbBlur = ImageColorAt($imgBlur, $x, $y);
               
                $rBlur = (($rgbBlur >> 16) & 0xFF);
                $gBlur = (($rgbBlur >> 8) & 0xFF);
                $bBlur = ($rgbBlur & 0xFF);
               
                $rNew = ($amount * ($rOrig - $rBlur)) + $rOrig;
                    if($rNew>255){$rNew=255;}
                    elseif($rNew<0){$rNew=0;}
                $gNew = ($amount * ($gOrig - $gBlur)) + $gOrig;
                    if($gNew>255){$gNew=255;}
                    elseif($gNew<0){$gNew=0;}
                $bNew = ($amount * ($bOrig - $bBlur)) + $bOrig;
                    if($bNew>255){$bNew=255;}
                    elseif($bNew<0){$bNew=0;}
                $rgbNew = ($rNew << 16) + ($gNew <<8) + $bNew;
                    ImageSetPixel($img, $x, $y, $rgbNew);
            }
        }
    }
    imagedestroy($imgCanvas);
    imagedestroy($imgBlur);
   
    return $img;

}

$img="thmb_ny50.jpg";
$amount=80;//(typically 50 - 200)
$radius=0.5;//(typically 0.5 - 1)
$threshold=3;//(typically 0 - 5)
$final= UnsharpMask($img, $amount, $radius, $threshold);
echo $final;
?>
Avatar billede coderdk Praktikant
13. juli 2008 - 23:07 #6
Du kalder den forkert. Den forventer en image resource... Derfor ændr det sidste af din kode til:

$imgfile="thmb_ny50.jpg";
$img = imagecreatefromjpeg($imgfile);
$amount=80;//(typically 50 - 200)
$radius=0.5;//(typically 0.5 - 1)
$threshold=3;//(typically 0 - 5)
$final= applyUnsharpMask($img, $amount, $radius, $threshold);
echo $final;
Avatar billede coderdk Praktikant
13. juli 2008 - 23:09 #7
Hvis du ikke vil bruge phpthumb er du jo nødt til at fjerne den fra koden og indsætte noget andet ;P
Avatar billede kaktus Nybegynder
13. juli 2008 - 23:41 #8
Nu er phpthumb helt ude af koden (har brugt en anden)............

<?php

/*

New:
- In version 2.1 (February 26 2007) Tom Bishop has done some important speed enhancements.
- From version 2 (July 17 2006) the script uses the imageconvolution function in PHP
version >= 5.1, which improves the performance considerably.


Unsharp masking is a traditional darkroom technique that has proven very suitable for
digital imaging. The principle of unsharp masking is to create a blurred copy of the image
and compare it to the underlying original. The difference in colour values
between the two images is greatest for the pixels near sharp edges. When this
difference is subtracted from the original image, the edges will be
accentuated.

The Amount parameter simply says how much of the effect you want. 100 is 'normal'.
Radius is the radius of the blurring circle of the mask. 'Threshold' is the least
difference in colour values that is allowed between the original and the mask. In practice
this means that low-contrast areas of the picture are left unrendered whereas edges
are treated normally. This is good for pictures of e.g. skin or blue skies.

Any suggenstions for improvement of the algorithm, expecially regarding the speed
and the roundoff errors in the Gaussian blur process, are welcome.

*/

function UnsharpMask($img, $amount, $radius, $threshold)    {

////////////////////////////////////////////////////////////////////////////////////////////////
////
////                  Unsharp Mask for PHP - version 2.1.1
////
////    Unsharp mask algorithm by Torstein Hønsi 2003-07.
////            thoensi_at_netcom_dot_no.
////              Please leave this notice.
////
///////////////////////////////////////////////////////////////////////////////////////////////



    // $img is an image that is already created within php using
    // imgcreatetruecolor. No url! $img 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)    $threshold = 255;
 
    $radius = abs(round($radius));    // Only integers make sense.
    if ($radius == 0) {
        return $img; imagedestroy($img); break;        }
    $w = imagesx($img); $h = imagesy($img);
    $imgCanvas = imagecreatetruecolor($w, $h);
    $imgBlur = imagecreatetruecolor($w, $h);
 

    // Gaussian blur matrix:
    //                     
    //    1    2    1     
    //    2    4    2     
    //    1    2    1     
    //                     
    //////////////////////////////////////////////////
     

    if (function_exists('imageconvolution')) { // PHP >= 5.1
            $matrix = array(
            array( 1, 2, 1 ),
            array( 2, 4, 2 ),
            array( 1, 2, 1 )
        );
        imagecopy ($imgBlur, $img, 0, 0, 0, 0, $w, $h);
        imageconvolution($imgBlur, $matrix, 16, 0);
    }
    else {

    // Move copies of the image around one pixel at the time and merge them with weight
    // according to the matrix. The same matrix is simply repeated for higher radii.
        for ($i = 0; $i < $radius; $i++)    {
            imagecopy ($imgBlur, $img, 0, 0, 1, 0, $w - 1, $h); // left
            imagecopymerge ($imgBlur, $img, 1, 0, 0, 0, $w, $h, 50); // right
            imagecopymerge ($imgBlur, $img, 0, 0, 0, 0, $w, $h, 50); // center
            imagecopy ($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h);

            imagecopymerge ($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 33.33333 ); // up
            imagecopymerge ($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 25); // down
        }
    }

    if($threshold>0){
        // Calculate the difference between the blurred pixels and the original
        // and set the pixels
        for ($x = 0; $x < $w-1; $x++)    { // each row
            for ($y = 0; $y < $h; $y++)    { // each pixel
                 
                $rgbOrig = ImageColorAt($img, $x, $y);
                $rOrig = (($rgbOrig >> 16) & 0xFF);
                $gOrig = (($rgbOrig >> 8) & 0xFF);
                $bOrig = ($rgbOrig & 0xFF);
             
                $rgbBlur = ImageColorAt($imgBlur, $x, $y);
             
                $rBlur = (($rgbBlur >> 16) & 0xFF);
                $gBlur = (($rgbBlur >> 8) & 0xFF);
                $bBlur = ($rgbBlur & 0xFF);
             
                // When the masked pixels differ less from the original
                // than the threshold specifies, they are set to their original value.
                $rNew = (abs($rOrig - $rBlur) >= $threshold)
                    ? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig))
                    : $rOrig;
                $gNew = (abs($gOrig - $gBlur) >= $threshold)
                    ? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig))
                    : $gOrig;
                $bNew = (abs($bOrig - $bBlur) >= $threshold)
                    ? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig))
                    : $bOrig;
             
             
                         
                if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew)) {
                        $pixCol = ImageColorAllocate($img, $rNew, $gNew, $bNew);
                        ImageSetPixel($img, $x, $y, $pixCol);
                    }
            }
        }
    }
    else{
        for ($x = 0; $x < $w; $x++)    { // each row
            for ($y = 0; $y < $h; $y++)    { // each pixel
                $rgbOrig = ImageColorAt($img, $x, $y);
                $rOrig = (($rgbOrig >> 16) & 0xFF);
                $gOrig = (($rgbOrig >> 8) & 0xFF);
                $bOrig = ($rgbOrig & 0xFF);
             
                $rgbBlur = ImageColorAt($imgBlur, $x, $y);
             
                $rBlur = (($rgbBlur >> 16) & 0xFF);
                $gBlur = (($rgbBlur >> 8) & 0xFF);
                $bBlur = ($rgbBlur & 0xFF);
             
                $rNew = ($amount * ($rOrig - $rBlur)) + $rOrig;
                    if($rNew>255){$rNew=255;}
                    elseif($rNew<0){$rNew=0;}
                $gNew = ($amount * ($gOrig - $gBlur)) + $gOrig;
                    if($gNew>255){$gNew=255;}
                    elseif($gNew<0){$gNew=0;}
                $bNew = ($amount * ($bOrig - $bBlur)) + $bOrig;
                    if($bNew>255){$bNew=255;}
                    elseif($bNew<0){$bNew=0;}
                $rgbNew = ($rNew << 16) + ($gNew <<8) + $bNew;
                    ImageSetPixel($img, $x, $y, $rgbNew);
            }
        }
    }
    imagedestroy($imgCanvas);
    imagedestroy($imgBlur);
 
    return $img;

}

$imgfile="thmb_ny50.jpg";
$img = imagecreatefromjpeg($imgfile);
$amount=80;//(typically 50 - 200)
$radius=0.5;//(typically 0.5 - 1)
$threshold=3;//(typically 0 - 5)

$final= UnsharpMask($img, $amount, $radius, $threshold);
echo $final;
?>
----------------------------------------
giver denne side
http://testkalender.sluk.dk/img/UnsharpMask.php

Resource id #2

jeg gad nok vide hvordan det er gjort her
http://vikjavev.no/computing/ump.php?id=254
Avatar billede coderdk Praktikant
14. juli 2008 - 00:41 #9
erstat

echo $final;

med:

header("Content-Type: image/jpeg");
imagejpeg($final);
Avatar billede kaktus Nybegynder
14. juli 2008 - 11:29 #10
Ja se det hjalp......TAK coderdk
MEN hvad nu hvis jeg vil have vist et sammenlinings billede uden UnsharpMask ved siden af, som på siden hvor scriptet stammer fra..............
DENNE LINIE VISES IKKE
echo "<br /><img src=\"thmb_ny50.jpg\" title=\"samme uden UnsharpMask\"  />";
------------------------------------------------------------
jeg gad nok vide hvordan det er gjort her
http://vikjavev.no/computing/ump.php?id=254
Avatar billede coderdk Praktikant
14. juli 2008 - 11:51 #11
Scriptet du arbejder med, er ikke en side - Den producerer et billede...

Lav en ny side "test.php" med følgende indhold:

<img src="http://testkalender.sluk.dk/img/UnsharpMask.php" alt="Med unsharpmask" /><br /><br />
<img src="thmb_ny50.jpg" title="samme uden UnsharpMask" />
Avatar billede kaktus Nybegynder
14. juli 2008 - 12:51 #12
Ja men det er jo bare genialt det her...... heee
Resultat kan ses her http://testkalender.sluk.dk/img/index.php
MEN som der står øverst i det oprettede spørgsmål var tanken at mit upload script skulle "bruge" denne UnsharpMask funktion.......således at alle uploadede billeder var tilføjet UnsharpMask.......tror I det er muligt???
Jeg bruger som nævnt i spørgsmål denne funktion til skalering
<?
function skaler_jpg($img,$w,$h) {
$thumbnail = imagecreatetruecolor ($w, $h);
$billede = ImageCreateFromJpeg($img);
$billedstr = getimagesize($img);
imagecopyresized ($thumbnail, $billede, 0, 0, 0, 0, $w, $h, $billedstr[0], $billedstr[1]);
imagejpeg($thumbnail,$img,$jpegqual);
}
?>
Avatar billede coderdk Praktikant
14. juli 2008 - 13:49 #13
Naturligvis er det muligt :)

lige efter

imagecopyresized ($thumbnail, $billede, 0, 0, 0, 0, $w, $h, $billedstr[0], $billedstr[1]);

sæt ind:

$amount=80;//(typically 50 - 200)
$radius=0.5;//(typically 0.5 - 1)
$threshold=3;//(typically 0 - 5)
$thumbnail = UnsharpMask($thumbnail, $amount, $radius, $threshold);
Avatar billede coderdk Praktikant
14. juli 2008 - 13:49 #14
svar herfra :)
Avatar billede kaktus Nybegynder
14. juli 2008 - 15:15 #15
Det er sku rent legetøj det her...... hee
Jeg kan oplyse at når der skruges op for effekten stiger filstørrelsen ligefrem proportionel med ca. 8-10%.....
MEN ved moderat brug kan der klart opnås "tydeligere" billeder til webbrug......
TAK for hjælpen og point er velfortjent dine...
Avatar billede coderdk Praktikant
14. juli 2008 - 15:52 #16
Yep, det er dog ikke alle billeder der egner sig til unsharp, eller bliver bedere - men det er et genialt filter :)

Tak for point :)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester