2010. 7. 1.

PHP 이미지 crop

<iframe name="cropFrame" width="60" height="50" scrolling="no" style="display:none;"></iframe>
<form action="crop.php" method="post" target="cropFrame">
    <input id="imageSrc" type="hidden" name="imageSrc" value="" />
    <input id="x" type="hidden" name="x" value="0" />
    <input id="y" type="hidden" name="y" value="0" />
    <input id="w" type="hidden" name="w" value="450" />
    <input id="h" type="hidden" name="h" value="200" />
    <input type="submit" value="crop" />
</form>

----------------------------------------------------------------------

<?php
    require_once './FirePHPCore/FirePHP.class.php';
    $firephp = FirePHP::getInstance(true);

    //$firephp->log($_POST['imageSrc']);
    
    $imageSrc = $_POST['imageSrc'];
    $x = $_POST['x'];
    $y = $_POST['y'];
    $w = $_POST['w'];  // 높이
    $h = $_POST['h'];   // 길이

    $target_w = 450;
    $target_h = 200;
    $jpeg_quality = 90;
    $src = substr($imageSrc, 2);
    $img_r = imagecreatefromjpeg($src);
    $dst_r = ImageCreateTrueColor($w, $h);

    imagecopyresampled(
        $dst_r,
        $img_r,
        0, 0, $x, $y,
        $target_w, $target_h, $w, $h
    );

    $output_filename = './pic/test.jpg';

    header('Content-type: image/jpeg');
    imagejpeg($dst_r, $output_filename, $jpeg_quality);
?>

imagecreatefromjpeg($src);
 - 해당 경로의 파일을 jpeg 이미지로 생성함

ImageCreateTrueColor($w, $h);
 - 파라미터로 받은 넓이와 높이의 크기만한 검정색 이미지를 생성함

imagecopyresampled(
    $dst_r, // 타겟 이미지
    $img_r,  // 복사할 이미지
    0,         // 타겟 이미지의 x좌표
    0,         // 타겟 이미지의 y좌표
    $x,       // 원본 이미지의 x좌표
    $y,       // 원본 이미지의 y좌표
    $target_w, // 타겟 이미지의 넓이
    $target_h,  // 타겟 이미지의 높이
    $w,      // 원본 이미지의 넓이
    $h        // 원본 이미지의 높이
);
 - 이미지의 크기를 변경해서 복사함
 - 이미지의 x, y 좌표는 좌상단 모서리에서 시작함

PHP 파일업로드

<iframe name="uploadFrame" width="60" height="50" scrolling="no" style="display:none;"></iframe>
<form action="upload.php" method="post" enctype="multipart/form-data" target="uploadFrame"/>
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
    <label for="userfile">Upload a file:</label>
    <input type="file" name="userfile" id="userfile" />
    <input type="submit" value="Send File" />
</form>

---------------------------------------------------------------------

<?php
file_exists($filepath);
 - 파일경로를 파라미터로 넘겨주고 존재 여부를 Boolean으로 받음

 move_uploaded_file($_FILES['userfile']['tmp_name'], $path);
 - 파일을 해당 경로에 업로드함
?>



웹폼디자인


웹 폼 디자인 : 고객을 끌어당기는 폼 디자인의 원리 - 도서출판 ...

이미지출처 : insightbook.springnote.com

UX에 대한 관심이 높아져서 이 분야에 종사하는 분께 추천을 받았다. 요즘 웹 폼을 만들면서 책에 대한 흥미도가 높아졌고, 실제로 많이 도움이 된다. 웹 폼에 대한 이렇게 다양한 고민을 함께 할 수 있기에 너무 유익한 책이다. 웹 폼에 한정되어 있어 아쉽긴 하지만 폼에 관해선 왠만한 경우의 수를 다 고려한 느낌이 묻어난다.
앞으로 다른 UX에 관한 책들도 많이 읽어봐야겠다. 요즘엔 개발자도 디자이너도 UX를 고려해야 한다고 생각하는 사람으로 매우 추천할 만 하다.