<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.image.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.imagecreatefromstring.php',
    1 => 'imagecreatefromstring',
    2 => 'Create a new image from the image stream in the string',
  ),
  'up' => 
  array (
    0 => 'ref.image.php',
    1 => 'GD and Image Functions',
  ),
  'prev' => 
  array (
    0 => 'function.imagecreatefrompng.php',
    1 => 'imagecreatefrompng',
  ),
  'next' => 
  array (
    0 => 'function.imagecreatefromtga.php',
    1 => 'imagecreatefromtga',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/image/functions/imagecreatefromstring.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.imagecreatefromstring" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imagecreatefromstring</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">imagecreatefromstring</span> &mdash; <span class="dc-title">Create a new image from the image stream in the string</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.imagecreatefromstring-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>imagecreatefromstring</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$data</code></span>): <span class="type"><span class="type"><a href="class.gdimage.php" class="type GdImage">GdImage</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>imagecreatefromstring()</strong></span> returns an image identifier
   representing the image obtained from the given <code class="parameter">data</code>.
   These types will be automatically detected if your build of PHP supports 
   them: JPEG, PNG, GIF, BMP, WBMP, GD2, WEBP and AVIF.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.imagecreatefromstring-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">data</code></dt>
     <dd>
      <p class="para">
       A string containing the image data.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.imagecreatefromstring-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   An image object will be returned on success. <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> is returned if
   the image type is unsupported, the data is not in a recognised format,
   or the image is corrupt and cannot be loaded.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.imagecreatefromstring-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   <span class="function"><strong>imagecreatefromstring()</strong></span> raises an E_WARNING level error,
   if the data is not in a recognized format.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.imagecreatefromstring-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       On success, this function returns a <span class="classname"><a href="class.gdimage.php" class="classname">GDImage</a></span> instance now;
       previously, a <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> was returned.
      </td>
     </tr>

     <tr>
      <td>7.3.0</td>
      <td>
       WEBP is supported now (if supported by the libgd in use).
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.imagecreatefromstring-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-2871">
    <p><strong>Example #1 <span class="function"><strong>imagecreatefromstring()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$data </span><span style="color: #007700">= </span><span style="color: #DD0000">'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'<br />       </span><span style="color: #007700">. </span><span style="color: #DD0000">'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'<br />       </span><span style="color: #007700">. </span><span style="color: #DD0000">'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'<br />       </span><span style="color: #007700">. </span><span style="color: #DD0000">'8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg=='</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$data </span><span style="color: #007700">= </span><span style="color: #0000BB">base64_decode</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$im </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecreatefromstring</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br />if (</span><span style="color: #0000BB">$im </span><span style="color: #007700">!== </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br />    </span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-Type: image/png'</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">imagepng</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">);<br />}<br />else {<br />    echo </span><span style="color: #DD0000">'An error occurred.'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output
something similar to:</p></div>
    <div class="mediaobject">
     
     <div class="imageobject">
      <img src="images/21009b70229598c6a80eef8b45bf282b-imagecreatefromstring.png" alt="Output of example : imagecreatefromstring()" width="28" height="18" />
     </div>
    </div>
   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.imagecreatefromstring-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.imagecreatefromjpeg.php" class="function" rel="rdfs-seeAlso">imagecreatefromjpeg()</a> - Create a new image from file or URL</span></li>
   <li><span class="function"><a href="function.imagecreatefrompng.php" class="function" rel="rdfs-seeAlso">imagecreatefrompng()</a> - Create a new image from file or URL</span></li>
   <li><span class="function"><a href="function.imagecreatefromgif.php" class="function" rel="rdfs-seeAlso">imagecreatefromgif()</a> - Create a new image from file or URL</span></li>
   <li><span class="function"><a href="function.imagecreatetruecolor.php" class="function" rel="rdfs-seeAlso">imagecreatetruecolor()</a> - Create a new true color image</span></li>
  </ul>
 </div>

</div><?php manual_footer($setup); ?>