【问题标题】:Download low resolution image instead of high resolution in php在php中下载低分辨率图像而不是高分辨率
【发布时间】:2016-10-13 23:02:22
【问题描述】:

我开发了一个社交 android 应用程序,用户将 high quality image 上传到我的服务器,然后下载它们以显示在应用程序提要的列表视图中。

上传的图片保存在./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";
}


?>

现在我想将每个imagelow resolution 保存在不同的目录中(或实时获取低分辨率)并获取它的url 并使用php 发送到android 应用程序,我的应用程序中的用户可以在下载整个 image 之前,请查看图像的 thumbnail 或低 resolution

我应该怎么做?

【问题讨论】:

  • 你可以下载timthumb.php并上传到服务器,你可以使用timthumb.php后的图片路径?scr=image.jpg&h=height&w=width&zc=cropstyle(1,2,3)@ 987654322@
  • 你的意思是重新采样图像? ,看看这个 [stackoverflow.com/questions/4754594/…
  • 我不是 php 专家,也不知道如何正确使用它。你能告诉我如何将这些代码添加到我的 php 文件中吗? @Manikiran 先生

标签: php android image image-processing


【解决方案1】:

简单。您可以使用下面的代码来执行此操作:

<?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);
?>

【讨论】:

    猜你喜欢
    • 2011-04-07
    • 2014-11-20
    • 2017-08-23
    • 1970-01-01
    • 1970-01-01
    • 2011-02-11
    • 2012-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多