2014-02-18 3 views
0

이미지를 자르는이 스크립트가 있습니다. 어떻게 서버에 저장합니까?PHP로 자른 이미지 저장

move_uploaded_file($_FILES["file"]["tmp_name"], 
    "pictures/" . $_FILES["file"]["name"]); 





$imgSrc = 'pictures/' . $_FILES["file"]["name"]; 

//getting the image dimensions 
list($width, $height) = getimagesize($imgSrc); 

//saving the image into memory (for manipulation with GD Library) 
$myImage = imagecreatefromjpeg($imgSrc); 

// calculating the part of the image to use for thumbnail 
if ($width > $height) { 
    $y = 0; 
    $x = ($width - $height)/2; 
    $smallestSide = $height; 
} else { 
    $x = 0; 
    $y = ($height - $width)/2; 
    $smallestSide = $width; 
} 

// copying the part into thumbnail 
$thumbSize = 100; 
$thumb = imagecreatetruecolor($thumbSize, $thumbSize); 
imagecopyresampled($thumb, $myImage, 0, 0, $x, $y, $thumbSize, $thumbSize,  $smallestSide, $smallestSide); 

//final output 
header('Content-type: image/jpeg'); 
imagejpeg($thumb); 

이미지에서 볼 수 있듯이 출력 할 수 있습니다. 그러나 나는 그것을 구할 수 없습니다. 미리 :) 감사

+0

자르기 후 어떤 유형의 이미지도 저장하고 싶습니다. 그래서 기본적으로 $ end 변수는 결국 저장해야합니다. –

답변

0

두 번째 인수, 두 번째 인수는 인수로 파일 이름에 소요

imagejpeg($thumb, 'filename'); 

예를

imagejpeg($thumb, 'uploads/yourfilename.jpg'); 
+0

몇 가지 설명을 함께 제공하십시오. 그것은 학습자에게 도움이 될 것입니다! –

0

사용 http://nl1.php.net/move_uploaded_file 저장하기 위해 지정된 경로에 저장을 제공하십시오 파일

move_uploaded_file($_FILES['file']['tmp_name'], "dir/".$_FILES['file']['name']); 

또는 사용 이미지 jpeg하지만 jpeg에 충실해야합니다. .

관련 문제