최근에 이미지를 업로드하기위한 스크립트를 작성했습니다. 모든 것이 잘 작동합니다. 하지만 이제 이미지를 업로드 한 후에 크기를 조정하려고합니다. 몇 가지 연구를 해본 결과 <canvas>
요소로 시험해보고 싶습니다. 나는 스크립트의 일부를 가지고 있으며, 다른 것들은 누락되어 있으며 모든 것을 연결하는 방법을 모른다. 업로드하기 전에 캔버스로 이미지 크기 조정
이
이 단계는 다음과 같습니다이
img/uploads
에 이미지를 업로드 - 완료.<form action="picupload.php" method="post" enctype="multipart/form-data"> <input name="uploadfile" type="file" accept="image/jpeg, image/png"> <input type="submit" name="btn[upload]"> </form>
picupload.php : 캔버스 요소에 이미지를 넣어
$tmp_name = $_FILES['uploadfile']['tmp_name']; $uploaded = is_uploaded_file($tmp_name); $upload_dir = "img/uploads"; $savename = "[several code]";
if($uploaded == 1) { move_uploaded_file ( $_FILES['uploadfile']['tmp_name'] , "$upload_dir/$savename"); }
-
은 크기를 조정 누락 - 코드 I의 일부 어떻게 든 사용하고 싶다 :
var MAX_WIDTH = 400; var MAX_HEIGHT = 300; var width = img.width; var height = img.height; if (width > height) { if (width > MAX_WIDTH) { height *= MAX_WIDTH/width; width = MAX_WIDTH; } } else { if (height > MAX_HEIGHT) { width *= MAX_HEIGHT/height; height = MAX_HEIGHT; } }
기존 이미지를 새 크기 조정 된 이미지로 바꿉니다. - 누락 됨
누군가가 나에게 끝내기위한 몇 가지 팁을 주시면 매우 좋을 것입니다. - 감사합니다!
글쎄, 어떻게 이미지를 업로드하나요? – Adjit
@Adjit 추가했습니다;) –
이미지 잡기 - http://stackoverflow.com/questions/4459379/preview-an-image-before-it-is-uploaded; 캔버스에 이미지를 추가하는 경우 - http://stackoverflow.com/questions/6011378/how-to-add-image-to-canvas – Adjit