메뉴 건너뛰기

프로그램언어

조회 수 258 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
<?
class Image {
    
    var $file;
    var $image_width;
    var $image_height;
    var $width;
    var $height;
    var $ext;
    var $types = array('','gif','jpeg','png','swf');
    var $quality = 80;
    var $top = 0;
    var $left = 0;
    var $crop = false;
    var $type;
    
    function Image($name='') {
        $this->file = $name;
        $info = getimagesize($name);
        $this->image_width = $info[0];
        $this->image_height = $info[1];
        $this->type = $this->types[$info[2]];
        $info = pathinfo($name);
        $this->dir = $info['dirname'];
        $this->name = str_replace('.'.$info['extension'], '', $info['basename']);
        $this->ext = $info['extension'];
    }
    
    function dir($dir='') {
        if(!$dir) return $this->dir;
        $this->dir = $dir;
    }
    
    function name($name='') {
        if(!$name) return $this->name;
        $this->name = $name;
    }
    
    function width($width='') {
        $this->width = $width;
    }
    
    function height($height='') {
        $this->height = $height;
    }
    
    function resize($percentage=50) {
        if($this->crop) {
            $this->crop = false;
            $this->width = round($this->width*($percentage/100));
            $this->height = round($this->height*($percentage/100));
            $this->image_width = round($this->width/($percentage/100));
            $this->image_height = round($this->height/($percentage/100));
        } else {
            $this->width = round($this->image_width*($percentage/100));
            $this->height = round($this->image_height*($percentage/100));
        }
        
    }
    
    function crop($top=0, $left=0) {
        $this->crop = true;
        $this->top = $top;
        $this->left = $left;
    }
    
    function quality($quality=80) {
        $this->quality = $quality;
    }
    
    function show() {
        $this->save(true);
    }
    
    function save($show=false) {
 
        if($show) @header('Content-Type: image/'.$this->type);
        
        if(!$this->width && !$this->height) {
            $this->width = $this->image_width;
            $this->height = $this->image_height;
        } elseif (is_numeric($this->width) && empty($this->height)) {
            $this->height = round($this->width/($this->image_width/$this->image_height));
        } elseif (is_numeric($this->height) && empty($this->width)) {
            $this->width = round($this->height/($this->image_height/$this->image_width));
        } else {
            if($this->width<=$this->height) {
                $height = round($this->width/($this->image_width/$this->image_height));
                if($height!=$this->height) {
                    $percentage = ($this->image_height*100)/$height;
                    $this->image_height = round($this->height*($percentage/100));
                }
            } else {
                $width = round($this->height/($this->image_height/$this->image_width));
                if($width!=$this->width) {
                    $percentage = ($this->image_width*100)/$width;
                    $this->image_width = round($this->width*($percentage/100));
                }
            }
        }
        
        if($this->crop) {
            $this->image_width = $this->width;
            $this->image_height = $this->height;
        }
 
        if($this->type=='jpeg') $image = imagecreatefromjpeg($this->file);
        if($this->type=='png') $image = imagecreatefrompng($this->file);
        if($this->type=='gif') $image = imagecreatefromgif($this->file);
        
        $new_image = imagecreatetruecolor($this->width, $this->height);
        imagecopyresampled($new_image, $image, 0, 0, $this->top, $this->left, $this->width, $this->height, $this->image_width, $this->image_height);
        
        $name = $show ? null: $this->dir.DIRECTORY_SEPARATOR.$this->name.'.'.$this->ext;
    
        if($this->type=='jpeg') imagejpeg($new_image, $name, $this->quality);
        if($this->type=='png') imagepng($new_image, $name);
        if($this->type=='gif') imagegif($new_image, $name);
 
        imagedestroy($image); 
        imagedestroy($new_image);
        
    }
    
}
  
 
/*  사용방법
$re_image = new Image(이미지 파일명);
$re_image -> width(200);
$re_image -> height(300);
$re_image -> save();
*/
?>

 


  1. No Image 07Feb
    by
    2024/02/07 Views 65 

    PHP 버전 숨기기 ( php version hide )

  2. No Image 12Jan
    by
    2023/01/12 Views 358 

    php 암호화 복호화 , 간단한 암호화

  3. No Image 12Jan
    by
    2023/01/12 Views 231 

    PHP 디렉토리안에 파일 리스트 가져오기

  4. No Image 12Jan
    by
    2023/01/12 Views 280 

    그누보드 https 보안서버 연결시 오류

  5. No Image 12Jan
    by
    2023/01/12 Views 178 

    php 두날짜 사이의 모든날짜 배열 만들기

  6. php 간단 심플한 달력만들기

  7. 간단한 캡차파일 만들기 captcha

  8. No Image 12Jan
    by
    2023/01/12 Views 197 

    PHP str_replace php 문자열치환

  9. No Image 12Jan
    by
    2023/01/12 Views 328 

    curl을 이용하여 post, get 방식 으로 데이터 전송하기

  10. No Image 12Jan
    by 조쉬
    2023/01/12 Views 258 

    php 이미지 리사이징 image resizing

  11. No Image 12Jan
    by
    2023/01/12 Views 251 

    PHP ZIP 압축파일 만들기

  12. No Image 12Jan
    by
    2023/01/12 Views 227 

    ereg(), eregi(), ereg_replace(), eregi_replace(), split() 대체

  13. No Image 12Jan
    by
    2023/01/12 Views 253 

    PHP 브라우저 알아내기

  14. No Image 12Jan
    by
    2023/01/12 Views 216 

    PHP SimpleHtmlDom Parser로 HTML 파싱하기

  15. No Image 12Jan
    by
    2023/01/12 Views 225 

    웹페이지 파싱

  16. No Image 12Jan
    by
    2023/01/12 Views 216 

    폴더 용량 체크

  17. No Image 12Jan
    by
    2023/01/12 Views 213 

    코드 생성 하기

  18. No Image 12Jan
    by
    2023/01/12 Views 292 

    PHP웹 보안 취약점 TOP5(웹해킹)

  19. No Image 12Jan
    by
    2023/01/12 Views 236 

    PHP 하위 디렉토리 포함 디렉토리 리스트 출력

  20. No Image 12Jan
    by
    2023/01/12 Views 229 

    PHP 파일 업로드 FORM 처리

Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved