<?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 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.imagecreate.php',
    1 => 'imagecreate',
    2 => '创建新的基于调色板的图像',
  ),
  'up' => 
  array (
    0 => 'ref.image.php',
    1 => 'GD 和图像处理 函数',
  ),
  'prev' => 
  array (
    0 => 'function.imagecopyresized.php',
    1 => 'imagecopyresized',
  ),
  'next' => 
  array (
    0 => 'function.imagecreatefromavif.php',
    1 => 'imagecreatefromavif',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/image/functions/imagecreate.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.imagecreate" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imagecreate</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">imagecreate</span> &mdash; <span class="dc-title">创建新的基于调色板的图像</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.imagecreate-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>imagecreate</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$width</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$height</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>imagecreate()</strong></span> 返回代表指定大小的空白图像的图像标识符。
  </p>
  <p class="para">
   通常，建议使用 <span class="function"><a href="function.imagecreatetruecolor.php" class="function">imagecreatetruecolor()</a></span> 而不是
   <span class="function"><strong>imagecreate()</strong></span>，以便在尽可能的最高质量图像上进行图像处理。如果要输出调色板图像，则应在使用
   <span class="function"><a href="function.imagepng.php" class="function">imagepng()</a></span> 或 <span class="function"><a href="function.imagegif.php" class="function">imagegif()</a></span> 保存图像之前立即调用 <span class="function"><a href="function.imagetruecolortopalette.php" class="function">imagetruecolortopalette()</a></span>。
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.imagecreate-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">width</code></dt>
     <dd>
      <p class="para">
       图像宽度。
      </p>
     </dd>
    
    
     <dt><code class="parameter">height</code></dt>
     <dd>
      <p class="para">
       图像高度。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.imagecreate-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">成功后返回图象对象,失败后返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。</p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.imagecreate-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       成功时，此函数现在返回 <span class="classname"><a href="class.gdimage.php" class="classname">GDImage</a></span> 实例，之前返回 <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.imagecreate-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 
     创建新的 GD 图像流并输出图像。
    </strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />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">$im </span><span style="color: #007700">= @</span><span style="color: #0000BB">imagecreate</span><span style="color: #007700">(</span><span style="color: #0000BB">110</span><span style="color: #007700">, </span><span style="color: #0000BB">20</span><span style="color: #007700">)<br />    or die(</span><span style="color: #DD0000">"Cannot Initialize new GD image stream"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$background_color </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecolorallocate</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$text_color </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecolorallocate</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">, </span><span style="color: #0000BB">233</span><span style="color: #007700">, </span><span style="color: #0000BB">14</span><span style="color: #007700">, </span><span style="color: #0000BB">91</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">imagestring</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">5</span><span style="color: #007700">, </span><span style="color: #0000BB">5</span><span style="color: #007700">,  </span><span style="color: #DD0000">"A Simple Text String"</span><span style="color: #007700">, </span><span style="color: #0000BB">$text_color</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 /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>以上示例的输出类似于：</p></div>
    <div class="mediaobject">
     
     <div class="imageobject">
      <img src="images/21009b70229598c6a80eef8b45bf282b-imagecreate.png" alt="示例输出：创建新的 GD 图像流并输出图像。" width="110" height="25" />
     </div>
    </div>
   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.imagecreate-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.imagecreatetruecolor.php" class="function" rel="rdfs-seeAlso">imagecreatetruecolor()</a> - 新建真彩色图像</span></li>
  </ul>
 </div>

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