Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- Session
- date
- MySQL
- composer-php
- post
- UTF-8
- string
- Laravel
- jquery
- 경영
- 웹하드추천
- Apache
- curl
- 웹하드순위
- function
- Linux
- Regex
- Forms
- HTML
- variables
- JSON
- Arrays
- 전략
- JavaScript
- file-upload
- 무료다운로드쿠폰
- php
- OOP
- Ajax
Archives
- Today
- Total
개발! 딱 깔끔하고 센스있게!
PHP 를 사용 하여 미리 보기 그림 을 만 듭 니 다.(사각형 으로 자 르 기) 본문
현재 사용 중인 phop 스 크 립 트 그림 이 있 습 니 다.
최대 너비 와 높이 에 기반 한 미리 보기 그림 을 만 듭 니 다.
하지만 항상 정사각형 그림 을 만 들 고 필요 할 때 그림 을 자 르 기 를 바 랍 니 다.
내 가 지금 사용 하 는 것 은:
function makeThumb( $filename, $type ) { global $max_width, $max_height; if ( $type == 'jpg' ) { $src = imagecreatefromjpeg("blocks/img/gallery/" . $filename); } else if ( $type == 'png' ) { $src = imagecreatefrompng("blocks/img/gallery/" . $filename); } else if ( $type == 'gif' ) { $src = imagecreatefromgif("blocks/img/gallery/" . $filename); } if ( ($oldW = imagesx($src)) < ($oldH = imagesy($src)) ) { $newW = $oldW * ($max_width / $oldH); $newH = $max_height; } else { $newW = $max_width; $newH = $oldH * ($max_height / $oldW); } $new = imagecreatetruecolor($newW, $newH); imagecopyresampled($new, $src, 0, 0, 0, 0, $newW, $newH, $oldW, $oldH); if ( $type == 'jpg' ) { imagejpeg($new, 'blocks/img/gallery/thumbs/'.$filename); } else if ( $type == 'png' ) { imagepng($new, 'blocks/img/gallery/thumbs/'.$filename); } else if ( $type == 'gif' ) { imagegif($new, 'blocks/img/gallery/thumbs/'.$filename); } imagedestroy($new); imagedestroy($src); }
이 걸 어떻게 바 꿔 서 내 가 원 하 는 걸 이 룰 수 있 을 까?
미리 감사합니다.
대답 하 다.
function makeThumb( $filename , $thumbSize=100 ){ global $max_width, $max_height; /* Set Filenames */ $srcFile = 'blocks/img/gallery/'.$filename; $thumbFile = 'blocks/img/gallery/thumbs/'.$filename; /* Determine the File Type */ $type = substr( $filename , strrpos( $filename , '.' )+1 ); /* Create the Source Image */ switch( $type ){ case 'jpg' : case 'jpeg' : $src = imagecreatefromjpeg( $srcFile ); break; case 'png' : $src = imagecreatefrompng( $srcFile ); break; case 'gif' : $src = imagecreatefromgif( $srcFile ); break; } /* Determine the Image Dimensions */ $oldW = imagesx( $src ); $oldH = imagesy( $src ); /* Calculate the New Image Dimensions */ if( $oldH > $oldW ){ /* Portrait */ $newW = $thumbSize; $newH = $oldH * ( $thumbSize / $newW ); }else{ /* Landscape */ $newH = $thumbSize; $newW = $oldW * ( $thumbSize / $newH ); } /* Create the New Image */ $new = imagecreatetruecolor( $thumbSize , $thumbSize ); /* Transcribe the Source Image into the New (Square) Image */ imagecopyresampled( $new , $src , 0 , 0 , ( $newW-$thumbSize )/2 , ( $newH-$thumbSize )/2 , $thumbSize , $thumbSize , $oldW , $oldH ); switch( $type ){ case 'jpg' : case 'jpeg' : $src = imagejpeg( $new , $thumbFile ); break; case 'png' : $src = imagepng( $new , $thumbFile ); break; case 'gif' : $src = imagegif( $new , $thumbFile ); break; } imagedestroy( $new ); imagedestroy( $src ); }
'개발 스크랩 메모 > PHP' 카테고리의 다른 글
PHP JSON encode () & My SQL 을 사용 하여 JSON 대상 으로 돌아 가 jQuery 함 수 를 전달 합 니 다. (0) | 2020.11.27 |
---|---|
지폐 텍스트 없 는 PHP 쇼 Money 격식 (0) | 2020.11.27 |
PhP 를 사용 하여 My Sql 에 저 장 된 비밀 번 호 를 암호 화 하 는 가장 좋 은 실천 은 무엇 입 니까? (0) | 2020.11.27 |
PHP: Zend Form Element 파일 로 올 린 파일 을 어떻게 바 꿉 니까? (0) | 2020.11.27 |
PHP: URL 의 방향 을 재 설정 하 시 겠 습 니까? (0) | 2020.11.27 |
Comments