imagecopyresampled 인수... 수학 잘하시는 분 있나요 ㅠ;

imagecopyresampled 인수... 수학 잘하시는 분 있나요 ㅠ;

QA

imagecopyresampled 인수... 수학 잘하시는 분 있나요 ㅠ;

본문

c32c98d3da82ae2e3c9a9efd1a315c10_1411315518_1572.gif

각기 다른 크기의 로고 이미지 파일을 첨부받아서

 

작은 썸네일을 만드는데,

 

썸네일의 크기는 고정이 되어 있습니다.

 

근데 그냥 단순하게 썸네일을 만든다면,

 

위에처럼 나타나지 않고, 크기가 늘어나서 비율이 깨지고 그렇게 되는데요.

 

위 사진처럼 나타나게 하고 싶거든요.

 

$src 는 색깔 사각형과 관련된 변수구요.

$dst 가 검정 사각형에 해당하는 거겠죠?

 

imagecopyresampled($dst, $src, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);

 

$src_x 와 $src_y 값만 구하면 해결이 되는 듯 한데... 뭐부터 시작해야될지 모르겠네요 ㅠ.ㅠ

 

 

 

 

 

 

 

이 질문에 댓글 쓰기 :

답변 2

http://mandeulgo.net/test.php

 


<?php
 
/*
imagecopyresampled($dst, $src, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
 
$src_x : 원본의 시작되는 x축 좌표
$src_y : 원본의 시작되는 y축 좌표
$dst_x : 사본의 시작되는 x축 좌표
$dst_y : 사본의 시작되는 y축 좌표
$src_w : 원본의 가로길이
$src_h : 원본의 세로길이
$dst_x : 사본의 가로길이
$dst_y : 사본의 세로길이
 
 
*/
 
$src_img = "/imgs/img_gen0016_01.jpg";
$src_img = "/home/gjm/public_html".$src_img;
 
thumb($src_img, 100 , 200,50,false);
 
function thumb($src,$quality,$w,$h,$saveas) { 
	list($width,$height)=getimagesize($src);
	$ratio = array($w / $width , $h / $height);
 
	// 작은 쪽을 기준으로 이미지를 변환
	if($ratio[0] > $ratio[1])
	{
		$dst['w'] = round($width * $ratio[1]);
		$dst['h'] = round($height * $ratio[1]);
		$dst['x'] = ($w - round($width * $ratio[1]) ) / 2;
		$dst['y'] = ($h - round($height * $ratio[1]) ) / 2;
	}
	else
	{
		$dst['w'] = round($width * $ratio[0]);
		$dst['h'] = round($height * $ratio[0]);
		$dst['x'] = ($w - round($width * $ratio[0]) ) / 2;
		$dst['y'] = ($h - round($height * $ratio[0]) ) / 2;
	}
	$dst_img = imagecreatetruecolor($dst['w'],$dst['h']); 
	$src_img = imagecreatefromjpeg($src);
 
 
	// 비율에 맞춰 썸네일 크기에 다 들어가도록 1차 변환
	imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst['w'], $dst['h'], $width, $height);
 
	$dst['image'] = imagecreatetruecolor($w, $h);
	imagealphablending($dst['image'], FALSE);
	imagesavealpha($dst['image'], TRUE);
 
	$transparent = imagecolorallocatealpha($dst['image'], 255, 255, 255, 127);
	imagefilledrectangle($dst['image'], 0, 0, $w, $h, $transparent);
 
	// 썸네일에 맞게 나오도록 2차 변환
	imagecopyresampled($dst['image'], $dst_img, $dst['x'], $dst['y'], 0, 0, $dst['w'], $dst['h'], $dst['w'], $dst['h']);
	header('Content-Type: image/jpeg');
	imagejpeg($dst['image'], null, 100);
 
}  

 

답변을 작성하시기 전에 로그인 해주세요.
전체 93
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1402호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT