0

I am writing app services for android app. I am using codeigniter. From android i am getting base64 string. I am trying to convert it to image. They are sending like $_POST[ base64string ] and i am converting like below.

          $data=base64_decode($_POST['signature_image']);

          $im=imagecreatefromstring($data);

          header('Content-Type: image/jpeg');

          imagepng($im,$loc_url.$imagename1);

          imagedestroy($im);

but it is not converting to image.We are using other server and there also we are using same app services. it is working there. I don't know what is the issue. I have tried increasing

  ini_set('post_max_size','250M'); 
  ini_set('upload_max_filesize','200M');

in my controller and model file. But it is not working. Please help me what is the issue and how it is resolve?

Mythili
  • 29
  • 1
  • 1
  • 5

1 Answers1

0

I think problem is that data:image/png;base64, included into base64 string. you need to 1st remove that and try again like bellow.

    $encoded = explode( ',', $_POST['signature_image'])[0];
    $data= base64_decode($encoded);
    ....
  • No it is not contain data:image/png;base64. it is looks like below: – Mythili Apr 21 '20 at 09:43
  • %2F9j%2F4AAQSkZJRgABAQAAAQABAAD%2F2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsK%0ACwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT%2F2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQU%0AFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT%2FwAARC – Mythili Apr 21 '20 at 09:44
  • @Mythili Please refer [link](https://stackoverflow.com/questions/15153776/convert-base64-string-to-an-image-file) may be solve your problem – Sejal Vadariya Apr 21 '20 at 12:08