Php 在ftp上调整图像大小(创建缩略图)

Php 在ftp上调整图像大小(创建缩略图),php,image,ftp,put,Php,Image,Ftp,Put,所以我有一个简单的目标,但我似乎无法让这一部分发挥作用 1) 上传一张图片,创建3种不同尺寸:LG、MD、SM;然后重命名图像 2) 将图像从服务器/网站A移动到服务器/网站B 我有上传和重命名的工作,为所有三个图像,但我不能找出我做错了重新调整部分。任何帮助都将不胜感激 注意:我目前正试图调整一张图片的大小,我想一次调整一张图片是最明智的,以确保我了解正在发生的事情 代码: function thumb\u resize\u image\u new($source、$destination、$

所以我有一个简单的目标,但我似乎无法让这一部分发挥作用

1) 上传一张图片,创建3种不同尺寸:LG、MD、SM;然后重命名图像

2) 将图像从服务器/网站A移动到服务器/网站B

我有上传和重命名的工作,为所有三个图像,但我不能找出我做错了重新调整部分。任何帮助都将不胜感激

注意:我目前正试图调整一张图片的大小,我想一次调整一张图片是最明智的,以确保我了解正在发生的事情

代码:

function thumb\u resize\u image\u new($source、$destination、$image\u type、$max\u size、$image\u width、$image\u height、$quality){

如果($image\u width您能告诉我们您遇到的具体问题吗?您希望发生什么以及实际发生了什么?告诉我们哪条线应该这样做也会很好。@River我实际上只是想我找到了一种解决问题的方法。我最初并没有让图像调整大小并移动到网站/服务器B。它只是在移动。但我目前通过上传到服务器/网站A,重新调整大小,重命名,然后我将其移动到B。如果您愿意,我可以上传或编辑此代码。但我很想知道如何在不实际上传任何内容到服务器A的情况下完成这一切。
function thumb_resize_image_new($source, $destination, $image_type, $max_size, $image_width, $image_height, $quality){

    if($image_width <= 0 || $image_height <= 0){return false;} //return false if nothing to resize

    //do not resize if image is smaller than max size
    if($image_width <= $max_size && $image_height <= $max_size){
        return true;
    }

    //Construct a proportional size of new image
    $image_scale = min($max_size/$image_width, $max_size/$image_height);
    $new_width = ceil($image_scale * $image_width);
    $new_height = ceil($image_scale * $image_height);

    $new_canvas = imagecreatetruecolor( $new_width, $new_height ); //Create a new true color image
    imagealphablending($new_canvas,true);
    $success = imagecopyresampled($new_canvas, $source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);

    return true;
}
if(isset($_POST['sendFile'])) { 
    $image_name = $_FILES['image_file']['name']; //file name
    $destination_folder = "folder/";
    $sm_square_size = 300; //Thumbnails will ! be cropped 
    $sm_prefix = "_sm"; //Small thumb Prefix
    $md_square_size = 600; //Thumbnails will ! be cropped 
    $md_prefix = "_md"; //Medium thumb Prefix
    $max_image_size = 1200; //Maximum image size (height and width)
    $lg_prefix = "_lg"; //Large thumb Prefix
    $jpeg_quality = 90; //jpeg quality

    if($image_name != "") {
        $image_size = $_FILES['image_file']['size']; //file size
        $image_temp = $_FILES['image_file']['tmp_name']; //file temp
        $image_size_info = getimagesize($image_temp); //get image size
        //echo "Image ".$image_name." Uploaded. ";
        if($image_size_info){
            $image_width = $image_size_info[0]; //image width
            $image_height = $image_size_info[1]; //image height
            $image_type = $image_size_info['mime']; //image type
        } else {
            die("Make sure image file is valid!");
        }

        //switch statement below checks allowed image type 
        //as well as creates new image from given file 
        switch($image_type){
            case 'image/png':
                $image_res =  imagecreatefrompng($image_temp); break;
            case 'image/gif':
                $image_res =  imagecreatefromgif($image_temp); break;
            case 'image/jpeg': case 'image/pjpeg':
                $image_res = imagecreatefromjpeg($image_temp); break;
            default:
                $image_res = false;
        }

        if($image_res){
            //Get file extension and name to construct new file name 
            $image_info = pathinfo($image_name);
            $image_extension = strtolower($image_info["extension"]); //image extension
            $image_name_only = strtolower($image_info["filename"]);//file name only, no extension
            $dateRec = date('d-M-Y-h-i-s');

            //create a random name for new image (Eg: fileName_293749.jpg) ;
            $new_file_name = $dateRec. '_' .  rand(0, 9999);

            $thumb_name = $new_file_name.$sm_prefix.'.'.$image_extension;
            $medium_name = $new_file_name.$md_prefix.'.'.$image_extension;
            $large_name = $new_file_name.$lg_prefix.'.'.$image_extension;

            $thumb_path = $destination_folder.$thumb_name;
            $medium_path = $destination_folder.$medium_name;
            $large_path = $destination_folder.$large_name;


            $ftp_server = "";
            $ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
            $ftp_username = "";
            $ftp_userpass = "";
            $login_conn = ftp_login($ftp_conn, $ftp_username, $ftp_userpass) or die("Could not connect to ftp login");
            if((!$ftp_conn) || (!$login_conn)) {
                print "FTP connection failed!"; exit();
            } else {
                // upload a file

                if(thumb_resize_image_new($image_res, $image_temp, $image_type, $md_square_size, $image_width, $image_height, $jpeg_quality)) { 
                    echo "thumb created. $success <br />";
                } else { 
                    die('Error Creating thumbnail: '.$thumb_path.'<br />'); 
                }

                if(ftp_put($ftp_conn, $thumb_path, $image_temp, FTP_BINARY)) {
                    echo "Successfully uploaded $thumb_name <hr />";
                } else {
                    echo "There was a problem while uploading $thumb_name into $thumb_path <hr />";
                }

                if(ftp_put($ftp_conn, $medium_path, $image_temp, FTP_BINARY)) {
                    echo "Successfully uploaded $medium_name <hr />";
                } else {
                    echo "There was a problem while uploading $medium_name into $medium_path <hr />";
                }

                if(ftp_put($ftp_conn, $large_path, $image_temp, FTP_BINARY)) {
                    echo "Successfully uploaded $large_name <hr />";
                } else {
                    echo "There was a problem while uploading $large_name into $large_path <hr />";
                }

            }
            ftp_close($ftp_conn);   
        }   
    }
}