함수를 호출할 때 $file_src로 지정되어있는 이미지 파일 경로를 넣어주시면 됩니다.
$newsize=imgresize("파일경로");
이렇게 사용하시면 newsize[0] 에 가로길이가, newsize[1]에 세로길이가 반환되겠죠?
====================================================================
<?
function imgresize($file_src) {
$size = getimagesize("$file_src");
$width = $size[0];
$height = $size[1];
$limit_h = 422;
$limit_w = 563;
$percentage_h = $height/$limit_h;
$percentage_w = $width/$limit_w;
if($height > $limit_h || $width > $limit_w) {
if(($height > $limit_h && $width > $limit_w && $percentage_w > $percentage_h) || ($height < $limit_h && $width > $limit_w))
{$percentage = $percentage_w;}
elseif(($height >= $limit_h && $width >= $limit_w && $percentage_w < $percentage_h) || ($height >= $limit_h && $width < $limit_w))
{$percentage = $percentage_h;}
} else {$percentage = 1;}
$resize_h = $height/$percentage;
$resize_w = $width/$percentage;
$newsize = array("$resize_w", "$resize_h");
return $newsize;
}
?>
댓글 0
팁&유틸
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
|---|---|---|---|---|
| 12 | php 이미지 리사이징 | 공수래 | 2024.02.11 | 179 |
| » | 이미지 사이즈 비율로 조정 | 공수래 | 2024.02.11 | 137 |
| 10 | 이미지 비율 유지 축소 | 공수래 | 2024.02.11 | 88 |
| 9 | PHP의 URL에서 이미지 저장 | 공수래 | 2024.02.11 | 309 |
| 8 | PHP에서 이미지 크기 조정 | 공수래 | 2024.02.11 | 181 |
| 7 | 이미지 태그의 width, height 스타일이 모두 명시되어야 하는 이유 | 공수래 | 2024.02.12 | 294 |
| 6 |
jQuery Waterwheel Carousel
| 공수래 | 2024.02.15 | 120 |
| 5 |
xampp php8.2 ffmpeg 설치
| 공수래 | 2024.02.24 | 164 |
| 4 |
Blackmagic DaVinci Resolve Studio 20.3 Patcher 사용법
| 공수래 | 2025.12.09 | 20 |
| 3 | 정규식 특정문자 또는 특수문자를 제거 | 공수래 | 2026.02.01 | 14 |
| 2 |
msOffice 365 정품인증
| 공수래 | 2026.02.22 | 4 |
| 1 | 도스명령어 | 공수래 | 2026.02.22 | 9 |
