在PHP中下载低分辨率图像而不是高分辨率

时间:2016-06-13 13:36:22

标签: php android image image-processing

我开发了一个社交Android应用,用户将high quality image上传到我的服务器,然后将其下载到应用Feed中的列表视图中显示。

./uploads/ directory in my server.中上传的图像保存我在PHP中使用以下代码将图像保存在服务器中:

  <?php

// Path to move uploaded files
 error_reporting(E_ALL ^ E_DEPRECATED);
include 'conf.php';
$target_path = "uploads/";

// array for final json respone
$response = array();

// getting server ip address
$server_ip = gethostbyname(gethostname());

// final file url that is being uploaded
$file_upload_url = 'http://' . $server_ip . '/' . 'AndroidFileUpload' . '/' . $target_path;


if (isset($_FILES['image']['name'])) {
    $target_path = $target_path . basename($_FILES['image']['name']);





    try {
        // Throws exception incase file is not being moved
        if (!move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {
            // make error flag true
            print "error1";

        }


print basename($_FILES['image']['name']);

    } catch (Exception $e) {
        // Exception occurred. Make error flag true
       print "error2";
    }
} else {
    // File parameter is missing
   print "error3";
}


?>

现在,我想将low resolution中的每个image保存在不同的目录中(或实时获得低分辨率)并获取url并使用php发送到我的应用中的Android应用和用户可以在下载整个thumbnail之前看到resolution或低image的图片。

我应该怎么做?

1 个答案:

答案 0 :(得分:0)

易。您可以使用以下代码执行此操作:

<?php
$org_info = getimagesize("source image");
echo $org_info[3] . '<br><br>';
$rsr_org = imagecreatefromjpeg("source image");
$rsr_scl = imagescale($rsr_org, new_width, new_height,  IMG_BICUBIC_FIXED);
imagejpeg($rsr_scl, "destination image");
imagedestroy($rsr_org);
imagedestroy($rsr_scl);
?>