title: Error: imagecreatefromstring(): Data is not in a recognized format laravel
body: <p>I am getting this error when I try to retrieve an image from the database, all I wanted to do is just print out the signature image in my view, can anyone help? I heard that the file might be corrupted or something or also it couldn't decode base64 yet I see them use encode on it? (quite confused on what to do) Thanks in advance</p>
  
  <p>I saved my image into the database through user input and put it into the database in binary format. ($table->binary('signature'); )</p>
  
  <p>Controller</p>
  
  <pre><code>    public function getInfo($id) {
  
        $data = personal_info::where('id',$id)-&gt;get();
  
        $imageDataEncoded = DB::table('personal_infos')-&gt;select('signature')-&gt;get(); //get image
      $imageData = base64_decode($imageDataEncoded);
      $source = imagecreatefromstring($imageData);
      $imageSave = imagejpeg($source);
      imagedestroy($source);
       return view('test',compact('data','imageSave'));
  }
  </code></pre>
  
  <p>view.blade.php</p>
  
  <pre><code>@foreach ($data as $object)
  &lt;b&gt;Signature: &lt;/b&gt;{{$object-&gt;$imageSave}}&lt;br&gt;&lt;br&gt;
  </code></pre>
  
  <p>If I remove this whole part at the controller and just used this in the view.blade.php, I won't get an error but I know it is wrong since I am supposed to convert it into an image which I had did. I saw from other forum that I need the path of the image but my image is stored in the database, so what am I supposed to do?</p>
  
  <p>Controller (if remove)</p>
  
  <pre><code>$imageDataEncoded = DB::table('personal_infos')-&gt;select('signature')-&gt;get(); //get image
          $imageData = base64_decode($imageDataEncoded);
          $source = imagecreatefromstring($imageData);
          $imageSave = imagejpeg($source);
          imagedestroy($source);
  </code></pre>
  
  <p>view.blade.php</p>
  
  <pre><code>@foreach ($data as $object)
  &lt;b&gt;Signature: &lt;/b&gt;{{base64_decode($object-&gt;$imageSave)}}&lt;br&gt;&lt;br&gt;
  </code></pre>
  
  <p>Get signature image from user using this:
  page1.blade.php</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;title&gt;Signature Pad&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  {!! Form::open(['url' =&gt; 'page1/submit']) !!}
  
  &lt;canvas id="signature-canvas" style="width:500px;height:200px;max-width:100%;border:1px #CCC solid;"&gt;&lt;/canvas&gt;
  
  &lt;div id="signature-message"&gt;&lt;/div&gt;
  
  &lt;div id="signature-buttons"&gt;
    &lt;input type="button" id="clear-signature-btn" value="Clear"&gt; 
    &lt;input type="button" id="save-signature-btn" value="Save"&gt;
  &lt;/div&gt;
  
  &lt;input type="hidden" name="signature" id="signature-data" value=""&gt;
  </code></pre>
  
  <p>SignatureController</p>
  
  <pre><code>public function submit(Request $request)
  {
  
      $data = array();
      $data['signature'] = $request-&gt;signature;
  </code></pre>
  
  <p>Getting this now: (why am I getting this?)
  <a href="https://i.stack.imgur.com/AQtWT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AQtWT.png" alt="enter image description here"></a></p>