채택완료

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

2014-09-22 (월) 01:10:36 3,899

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개

채택된 답변
+20 포인트

함수 사용방법을 알아야 하는 것이지 수학 잘할 필요는 없습니다

더하기 빼기만 할줄알면 됩니다

네이버/구글에서 GD로 검색해서 함수 사용방법을 알아보세요

http://mandeulgo.net/test.php

Copy
<?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); }

답변을 작성하려면 로그인이 필요합니다.