PHP 강좌PHP 이미지 필터 적용 예시

페이지 정보

no_profile 최고관리자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 작성일 21-06-23 09:46 1,973 0

본문

[code]

<?php


@error_reporting( E_ALL );

header("Content-Type: text/html; charset=UTF-8");




$filters = Array(

'IMG_FILTER_NEGATE'=>IMG_FILTER_NEGATE,

'IMG_FILTER_GRAYSCALE'=>IMG_FILTER_GRAYSCALE,

'IMG_FILTER_EDGEDETECT'=>IMG_FILTER_EDGEDETECT,

'IMG_FILTER_EMBOSS'=>IMG_FILTER_EMBOSS,

'IMG_FILTER_GAUSSIAN_BLUR'=>IMG_FILTER_GAUSSIAN_BLUR,

'IMG_FILTER_SELECTIVE_BLUR'=>IMG_FILTER_SELECTIVE_BLUR,

'IMG_FILTER_MEAN_REMOVAL'=>IMG_FILTER_MEAN_REMOVAL

);


$filters2 = Array(

'IMG_FILTER_BRIGHTNESS'=>Array(IMG_FILTER_BRIGHTNESS, 20, 40, 60, 80, 100),

'IMG_FILTER_ConTRAST'=>Array(IMG_FILTER_CONTRAST, 20, 40, 60, 80, 100),

'IMG_FILTER_SMOOTH'=>Array(IMG_FILTER_SMOOTH, -8, -6, -4, -2, 2, 4, 6, 8)

);


$args = range(0, 200, 100);




$face_file = 'study10_face.jpg'; // 얼굴 원본 사진




$i = 1;

foreach($filters as $name => $filter){


    $im = @imagecreatefromjpeg($face_file);

    imagefilter($im, $filter);


    imagepng($im , 'temp/study10_' . $i . '.png');

    @imagedestroy($im);


?>


필터 : <?php echo $name; ?><br>

<img src="temp/study10_<?php echo $i; ?>.png"><br><br><br>


<?

    $i++;

}




foreach($filters2 as $name => $array){


    $filter = array_shift($array);


    foreach($array as $level) {


        $im = @imagecreatefromjpeg($face_file);

        imagefilter($im, $filter, $level);


        imagepng($im , 'temp/study10_' . $i . '.png');

        @imagedestroy($im);


?>


필터 : <?php echo $name; ?> 레벨 : <?php echo $level; ?> <br>

<img src="temp/study10_<?php echo $i; ?>.png"><br><br><br>


<?

        $i++;

    }

}




$name = 'IMG_FILTER_COLORIZE';

$filter = IMG_FILTER_COLORIZE;


foreach($args as $args1){


    foreach($args as $args2){


        foreach($args as $args3){


        $im = @imagecreatefromjpeg($face_file);

        imagefilter($im, $filter, $args1, $args2, $args3);


        imagepng($im , 'temp/study10_' . $i . '.png');

        @imagedestroy($im);


?>


필터 : <?php echo $name; ?> R : <?php echo $args1; ?> G : <?php echo $args2; ?> B : <?php echo $args3; ?> <br>

<img src="temp/study10_<?php echo $i; ?>.png"><br><br><br>


<?

            $i++;

        }

    }

}


?>

[/code]

 

각종 필터 적용시 보여지는 것들을 쉽게 보여주는 예시입니다.

PHP 5.xx 이상 작동하며, GD 라이브러리 설치는 필수입니다.

추천 0

댓글목록