2012-09-19 2 views
0

jCrop을 사용하여 이미지를 자릅니다. 이 코드는 이전에 다른 페이지에서 작동했지만 다른 페이지에 대해 구현했을 때 재생되는 것으로 보입니다.PHP에서 이미지 자르기 imagecopyresampled - 자르기 대신 스쿼시 처리

이 코드를 실행하면 코드가 원본 이미지를 촬영하고 아래로 축소 한 다음 전체 이미지를 자르려고하는 상자에 맞 춥니 다.

값은 $ _POST 값에서 jCrop에서 올바르게 되돌려지고 있습니다.

$origURL=$_POST['CelebrityPicURL']; 
$x = $_POST['x']; 
$y = $_POST['y']; 
$w = $_POST['w']; 
$h = $_POST['h']; 

$targ_w = $targ_h = 300; 
$jpeg_quality = 90; 

$img_r = imagecreatefromjpeg($origURL); 
$dst_r = ImageCreateTrueColor($targ_w, $targ_h); 

imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'], 
$targ_w,$targ_h,$_POST['w'],$_POST['h']); 


imagejpeg($dst_r,$origURL,$jpeg_quality); 

답변

0

imagecopy()을 사용하면됩니다. 뭔가 ...

$dst_r = imagecreatetruecolor((int) $w, (int) $h); 
imagecopy($dst_r, $img_r, 0, 0, (int) $x, (int) $y, (int) $w, (int) $h); 

물론 범위 외 조건을 확인하고 적절하게 처리해야합니다. 왜 $_POST 배열에서 자르기 데이터를 가져 오는 경우 $targ_w$targ_h을 사용하는지 설정하고 있는지 잘 모릅니다.