1

I develop a social android app that users upload high quality image to my server and then download them to show in list view in app feed.

Uploaded image save in ./uploads/ directory in my server. I use the below code in PHP to save image in server:

  <?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";
}


?>

Now I want to save low resolution of every image in different directory(or in real time get low resolution ) and get url of it and using php send to android app and users in my app can see a thumbnail or low resolution of image before download whole image.

How I should do it?

  • Possible duplicate of [Creating a thumbnail from an uploaded image](http://stackoverflow.com/questions/11376315/creating-a-thumbnail-from-an-uploaded-image) – Manikiran Jun 13 '16 at 13:40
  • you can download timthumb.php and upload it on server and you can use the image path after timthumb.php?scr=image.jpg&h=height&w=width&zc=cropstyle(1,2,3) https://github.com/GabrielGil/TimThumb/blob/master/timthumb.php – Prateik Darji Jun 13 '16 at 13:42
  • you mean resampling the image ? , check this out [http://stackoverflow.com/questions/4754594/how-do-you-resize-a-high-resolution-picture-with-php] – ganero Jun 13 '16 at 13:51
  • I'm not expert in php and I don't know how use it correctly. can you tell me how add those code to my php file? Mr @Manikiran – Khaled Rostampour Jun 13 '16 at 13:51

1 Answers1

0

Easy. You can use the code below to do this :

<?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);
?>
Ratul Doley
  • 499
  • 1
  • 6
  • 12