0
votes

I have a form in my Android app that send information to php server with an image pick button. I want to resize image before saving on server with php codes :

<?php
  move_uploaded_file($_FILES['file']['tmp_name'],'uploads/'.$_FILES['file']
  ['name']);
  $orgfile='uploads/'.$_FILES['file']['name'];
  list($width,$height)=getimagesize($orgfile);
  $newfile=imagecreatefromjpeg($orgfile);
  $thumb='uploads/a/'.$_FILES['file']['name'];
  $truecolor=imagecreatetruecolor(600,400);
  imagecopyresampled($truecolor,$newfile,0,0,0,0,600,400,$width,$height);
  imagejpeg($truecolor,$thumb,100);
  unlink($orgfile);
?>

This code just resize jpeg images and another formats (png or gif and even jpg) saved a black image.

It is necessary to mention that name of image file changed to a random number like "32165465423" and I don't know the image format to use "imagecreatefrompng" or "imagecreatefromgif" in my php file.

I want a code like "imagecreatefromall" or another ...

Thanks guys(sorry for bad English)

1

1 Answers

0
votes

You will have to detect the type of image, based on that you can run the function. See the one cool php library for reference

https://github.com/eventviva/php-image-resize/blob/master/lib/ImageResize.php#L77