2017-06-07 6 views
0

私は写真の中心から自動作物イメージが必要です。これどうやってするの?最初に元の画像サイズをアップロードして、それを切り抜いてディレクトリに保存したいのです。ここでPhoto自動切り抜きの中心からのPHPの

が私のコードです:

<form name="photo" id="photo" method="post" action="photo_ac.php" enctype="multipart/form-data"> 
            <div class="form-group"> 
             <input type="file" id="photo_upload" name="photo_upload" class="form-control sa_file"> 
            </div> 
            <div class="sn_warning"> 

             <p> 
              By clicking 'Upload photo' you confirm that you have permission from the copyright holder. 
              <a href="#">Having problems uploading photos?</a> 
             </p> 

            </div> 
            <div class="save_cancl"> 

             <button class="btn btn-primary sv_cn_btn" type="submit">Upload Photo</button> 

            </div> 
           </form> 

アップロードコード:

<?php 

// IMAGE UPLOAD /////////////////////// 
    $folder = "gallery_photo/"; 
    $extention = strrchr($_FILES['photo_upload']['name'], "."); 
    $new_name = time(); 
    $photo_upload = $new_name.$extention; 
    $uploaddir = $folder . $photo_upload; 
    move_uploaded_file($_FILES['photo_upload']['tmp_name'], $uploaddir); 
////////////////////////////////////////////////// 



    //$insert_action = mysqli_query($con,"INSERT INTO `gallery_photos` (`id`, `user_id`, `photo_upload`) VALUES (NULL, '$user_id', '$photo_upload')"); 

?> 

私は$folder = "gallery_photo/thumbs"でそれをトリミングし、アップロードしたいともmysqlデータベースに挿入します。

+0

http://php.net/manual/en/book.imagick.phpは、http:// PHP。 net/manual/ja/imagick.cropthumbnailimage.php – Kazz

+0

私は適切な解決策が必要です –

答えて

0

元の画像をアップロードして画像の位置を渡した後に画像をトリミングすると、 の目的地と予想される幅、高さは幅に基づいて計算されます。

function create_thumb($src, $dest, $desired_width) { 

    /* read the source image */ 
    $source_image = imagecreatefromjpeg($src); 
    $width = imagesx($source_image); 
    $height = imagesy($source_image); 

    /* find the "desired height" of this thumbnail, relative to the desired width */ 
    $desired_height = floor($height * ($desired_width/$width)); 

    /* create a new, "virtual" image */ 
    $virtual_image = imagecreatetruecolor($desired_width, $desired_height); 

    /* copy source image at a resized size */ 
    imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height); 

    /* create the physical thumbnail image to its destination */ 
    imagejpeg($virtual_image, $dest, 100); 
} 

コード参考:Link

またはあなたのこの記事を参照することができます:Creating a thumbnail from an uploaded image

関連する問題