I have gotten the code to take an image from android and save it to my server, however I need to resize the image to a standard size. I have looked around and have not been able to get anything to work. Below is my code so far.
<?php
// Get image string
$base = $_REQUEST['image'];
// Get file name
$filename = $_REQUEST['filename'];
// Decode Image
$binary = base64_decode($base);
header('Content-Type: bitmap; charset=utf-8');
// Images will be saved
$file = fopen('/home1/skyrealm/public_html/img/'.$filename.'.jpg', 'wb');
if($file != true)
{
echo'Error uploading image';
}
else
{
// Create/Svae File
fwrite($file, $binary);
fclose($file);
echo 'Image upload successful';
}
?>
EDIT:
This is the code android side:
public void encodeImagetoString() {
new AsyncTask<Void, Void, String>() {
protected void onPreExecute() {
};
@Override
protected String doInBackground(Void... params) {
BitmapFactory.Options options = null;
options = new BitmapFactory.Options();
options.inSampleSize = 3;
bitmap = BitmapFactory.decodeFile(imgPath, options);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
// Must compress the Image to reduce image size to make upload easy
bitmap.compress(Bitmap.CompressFormat.PNG, 50, stream);
byte[] byte_arr = stream.toByteArray();
// Encode Image to String
encodedString = Base64.encodeToString(byte_arr, 0);
return "";
}
@Override
protected void onPostExecute(String msg) {
// Put converted Image string into Async Http Post param
params.put("image", encodedString);
// Trigger Image upload
triggerImageUpload();
}
}.execute(null, null, null);
}