English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP로 모호한 이미지 생성 방법 예제

PHP로 생성된 흐림 이미지 메서드를 설명하는 예제입니다. 여러분과 공유하고, 다음과 같이 구체적으로 설명합니다:

<?php
class image_blur{
/**
  * 이미지 고즈스 흐림(PNG에 적용)/jpg/gif 형식)
  * @param $srcImg 원본 이미지
  * @param $savepath 저장 경로
  * @param $savename 저장 이름
  * @param $positon 흐림 정도
  *
  *코드를 확장한 Martijn Frazer의 코드를 기반으로, Martijn Frazer에게 감사합니다.
  */
 public function gaussian_blur($srcImg,$savepath=null,$savename=null,$blurFactor=3{
  $gdImageResource=$this->image_create_from_ext($srcImg);
  $srcImgObj=$this->blur($gdImageResource,$blurFactor);
  $temp = pathinfo($srcImg);
  $name = $temp['basename'];
  $path = $temp['dirname'];
  $exte = $temp['extension'];
  $savename = $savename ? $savename : $name;
  $savepath = $savepath ? $savepath : $path;
  $savefile = $savepath .'/'. $savename;
  $srcinfo = @getimagesize($srcImg);
  switch ($srcinfo[2}) {
   case 1: imagegif($srcImgObj, $savefile); break;
   case 2: imagejpeg($srcImgObj, $savefile); break;
   case 3: imagepng($srcImgObj, $savefile); break;
   default: return '저장 실패'; //저장 실패
  }
  return $savefile;
  imagedestroy($srcImgObj);
 }
 /**
 * 강한 흐릿함
 *
 * @param $gdImageResource 이미지 자원
 * @param $blurFactor   선택할 수 있는 흐릿한 정도
 * 선택할 수 있는 흐릿한 정도 0 사용 3기본적으로 넘어서면5시간에 따라 매우 흐릿하게
 * @return GD 이미지 이미지 자원 타입
 * @author Martijn Frazer, idea based on http://stackoverflow.com/a/20264482
 */
 private function blur($gdImageResource, $blurFactor = 3)
 {}}
  // blurFactor는 정수여야 합니다
  $blurFactor = round($blurFactor);
  $originalWidth = imagesx($gdImageResource);
  $originalHeight = imagesy($gdImageResource);
  $smallestWidth = ceil($originalWidth * pow(0.5, $blurFactor));
  $smallestHeight = ceil($originalHeight * pow(0.5, $blurFactor));
  // 첫 번째 실행에서는 이전 이미지가 원본 입력입니다
  $prevImage = $gdImageResource;
  $prevWidth = $originalWidth;
  $prevHeight = $originalHeight;
  // scale way down and gradually scale back up, blurring all the way
  for($i = 0; $i < $blurFactor; $i += 1)
  {}}
   // determine dimensions of next image
   $nextWidth = $smallestWidth * pow(2, $i);
   $nextHeight = $smallestHeight * pow(2, $i);
   // resize previous image to next size
   $nextImage = imagecreatetruecolor($nextWidth, $nextHeight);
   imagecopyresized($nextImage, $prevImage, 0, 0, 0, 0,
    $nextWidth, $nextHeight, $prevWidth, $prevHeight);
   // apply blur filter
   imagefilter($nextImage, IMG_FILTER_GAUSSIAN_BLUR);
   // now the new image becomes the previous image for the next step
   $prevImage = $nextImage;
   $prevWidth = $nextWidth;
   $prevHeight = $nextHeight;
  }
  // scale back to original size and blur one more time
  imagecopyresized($gdImageResource, $nextImage,
  0, 0, 0, 0, $originalWidth, $originalHeight, $nextWidth, $nextHeight);
  imagefilter($gdImageResource, IMG_FILTER_GAUSSIAN_BLUR);
  // clean up
  imagedestroy($prevImage);
  // return result
  return $gdImageResource;
 }
 private function image_create_from_ext($imgfile)
 {}}
  $info = getimagesize($imgfile);
  $im = null;
  switch ($info[2}) {
  case 1: $im=imagecreatefromgif($imgfile); break;
  case 2: $im=imagecreatefromjpeg($imgfile); break;
  case 3: $im=imagecreatefrompng($imgfile); break;
  }
  return $im;
 }
}
$image_blur = new image_blur();
$image_blur->gaussian_blur("./1.jpg",null,null,3);
?>

원본 이미지 효과:

배경화면을 생성한 후의 효과:

PHP 관련 내용에 대해 더 많이 알고 싶은 독자는 다음 특辑을 확인해 주세요: 《PHP 그래픽 및 이미지 작업 기술 요약》、《php 파일 작업 요약》、《PHP 배열(Array) 작업 기술 전집》、《PHP 기본 문법 초보 강의》、《PHP 연산 및 연산자 사용 요약》、《php 오브젝트 지향 프로그래밍 초보 강의》、《PHP 네트워크 프로그래밍 기술 요약》、《php 문자열(string) 사용 요약》、《php+mysql 데이터베이스 작업 초보 강의》 및 《php 일반 데이터베이스 작업 기술 요약》

본 문서에 설명된 내용이 여러분의 PHP 프로그래밍에 도움이 되길 바랍니다.

고지사항: 본 문서의 내용은 인터넷에서 수집되었으며, 저작권은 원 저작자에게 있으며, 인터넷 사용자가 자발적으로 기여하고 업로드한 내용입니다. 본 사이트는 소유권을 가지지 않으며, 인공적인 편집을 하지 않았으며, 관련 법적 책임을 지지 않습니다. 저작권 문제가 있을 경우, 아래 이메일로 메일을 보내 주시기 바랍니다: notice#oldtoolbag.com(보고서를 작성할 때, #을 @으로 변경하십시오. 신고하고 관련 증거를 제공하시면, 사이트는 즉시 위반된 내용을 제거합니다.

좋아하는 것