uTools-Manuals/docs/php/imagecropauto.html
2019-04-28 19:00:34 +08:00

259 lines
9.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Crop an image automatically using one of the available modes</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.imagecropauto" class="refentry">
<div class="refnamediv">
<h1 class="refname">imagecropauto</h1>
<p class="verinfo">(PHP 5 &gt;= 5.5.0, PHP 7)</p><p class="refpurpose"><span class="refname">imagecropauto</span> &mdash; <span class="dc-title">Crop an image automatically using one of the available modes</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.imagecropauto-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>imagecropauto</strong></span>
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$image</code></span>
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$mode</code><span class="initializer"> = <strong><code>IMG_CROP_DEFAULT</code></strong></span></span>
[, <span class="methodparam"><span class="type">float</span> <code class="parameter">$threshold</code><span class="initializer"> = .5</span></span>
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$color</code><span class="initializer"> = -1</span></span>
]]] ) : <span class="type">resource</span></div>
<p class="para rdfs-comment">
Automatically crops an image according to the given
<code class="parameter">mode</code>.
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.imagecropauto-parameters">
<h3 class="title">参数</h3>
<dl>
<dt>
<code class="parameter">image</code></dt>
<dd>
<p class="para">由图象创建函数(例如<span class="function"><a href="imagecreatetruecolor.html" class="function">imagecreatetruecolor()</a></span>)返回的图象资源。</p></dd>
<dt>
<code class="parameter">mode</code></dt>
<dd>
<p class="para">
One of the following constants:
</p>
<dl>
<dt>
<strong><code>IMG_CROP_DEFAULT</code></strong></dt>
<dd>
<span class="simpara">
Same as <strong><code>IMG_CROP_TRANSPARENT</code></strong>.
Before PHP 7.4.0, the bundled libgd fell back to <strong><code>IMG_CROP_SIDES</code></strong>,
if the image had no transparent color.
</span>
</dd>
<dt>
<strong><code>IMG_CROP_TRANSPARENT</code></strong></dt>
<dd>
<span class="simpara">
Crops out a transparent background.
</span>
</dd>
<dt>
<strong><code>IMG_CROP_BLACK</code></strong></dt>
<dd>
<span class="simpara">
Crops out a black background.
</span>
</dd>
<dt>
<strong><code>IMG_CROP_WHITE</code></strong></dt>
<dd>
<span class="simpara">
Crops out a white background.
</span>
</dd>
<dt>
<strong><code>IMG_CROP_SIDES</code></strong></dt>
<dd>
<span class="simpara">
Uses the 4 corners of the image to attempt to detect the background to
crop.
</span>
</dd>
<dt>
<strong><code>IMG_CROP_THRESHOLD</code></strong></dt>
<dd>
<span class="simpara">
Crops an image using the given <code class="parameter">threshold</code> and
<code class="parameter">color</code>.
</span>
</dd>
</dl>
</dd>
<dt>
<code class="parameter">threshold</code></dt>
<dd>
<p class="para">
Specifies the tolerance in percent to be used while comparing the image
color and the color to crop. The method used to calculate the color
difference is based on the color distance in the RGB(a) cube.
</p>
<p class="para">
Used only in <strong><code>IMG_CROP_THRESHOLD</code></strong> mode.
</p>
<blockquote class="note"><p><strong class="note">Note</strong>:
<span class="simpara">
Before PHP 7.4.0, the bundled libgd used a somewhat different algorithm,
so the same <code class="parameter">threshold</code> yielded different results
for system and bundled libgd.
</span>
</p></blockquote>
</dd>
<dt>
<code class="parameter">color</code></dt>
<dd>
<p class="para">
Either an RGB color value or a palette index.
</p>
<p class="para">
Used only in <strong><code>IMG_CROP_THRESHOLD</code></strong> mode.
</p>
</dd>
</dl>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.imagecropauto-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
Returns a cropped image resource on success 或者在失败时返回 <strong><code>FALSE</code></strong>.
If the complete image was cropped, <span class="function"><a href="imagecrop.html" class="function">imagecrop()</a></span> returns <strong><code>FALSE</code></strong>.
</p>
</div>
<div class="refsect1 changelog" id="refsect1-function.imagecropauto-changelog">
<h3 class="title">更新日志</h3>
<table class="doctable informaltable">
<thead>
<tr>
<th>版本</th>
<th>说明</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td>7.4.0</td>
<td>
The behavior of imagecropauto() in the bundled libgd has been synced with
that of system libgd: <strong><code>IMG_CROP_DEFAULT</code></strong> no longer falls
back to <strong><code>IMG_CROP_SIDES</code></strong> and threshold-cropping now uses
the same algorithm as system libgd.
</td>
</tr>
<tr>
<td>7.4.0</td>
<td>
The default value of <code class="parameter">mode</code> has been changed to
<strong><code>IMG_CROP_AUTO</code></strong>. Formerly, the default value has been
<em>-1</em> which corresponds to <strong><code>IMG_CROP_DEFAULT</code></strong>,
but passing <em>-1</em> is now deprecated.
</td>
</tr>
</tbody>
</table>
</div>
<div class="refsect1 examples" id="refsect1-function.imagecropauto-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-3691">
<p><strong>Example #1 Proper handling of auto-cropping</strong></p>
<div class="example-contents"><p>
As noted in the return value section, <span class="function"><strong>imagecropauto()</strong></span>
returns <strong><code>FALSE</code></strong> if the whole image
was cropped. In this example we have an image resource
<em>$im</em> which should be automatically cropped only if there
is something to crop; otherwise we want to proceed with the original image.
</p></div>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$cropped&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecropauto</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">IMG_CROP_DEFAULT</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$cropped&nbsp;</span><span style="color: #007700">!==&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)&nbsp;{&nbsp;</span><span style="color: #FF8000">//&nbsp;in&nbsp;case&nbsp;a&nbsp;new&nbsp;image&nbsp;resource&nbsp;was&nbsp;returned<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">imagedestroy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;we&nbsp;destroy&nbsp;the&nbsp;original&nbsp;image<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$im&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$cropped</span><span style="color: #007700">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;and&nbsp;assign&nbsp;the&nbsp;cropped&nbsp;image&nbsp;to&nbsp;$im<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.imagecropauto-seealso">
<h3 class="title">参见</h3>
<ul class="simplelist">
<li class="member"><span class="function"><a href="imagecrop.html" class="function" rel="rdfs-seeAlso">imagecrop()</a> - Crop an image to the given rectangle</span></li>
</ul>
</div>
</div></div></div></body></html>