Skip to content

Commit

Permalink
Update image
Browse files Browse the repository at this point in the history
  • Loading branch information
mowangjuanzi committed Jan 17, 2025
1 parent cd677b3 commit 38cd583
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 90 deletions.
12 changes: 4 additions & 8 deletions reference/image/examples.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 10c69571e7dd8a7cc0fbc9f20a55d24b1b1032be Maintainer: yuanyuqiang Status: ready -->
<!-- Reviewed: no -->

<!-- EN-Revision: 9960a09a5705102bf4dd0ce63e03d9ec716d0015 Maintainer: yuanyuqiang Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<chapter xml:id="image.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
&reftitle.examples;
<section xml:id="image.examples-png">
Expand All @@ -21,7 +20,6 @@ $orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);
?>
]]>
Expand Down Expand Up @@ -60,10 +58,9 @@ $sy = imagesy($stamp);
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
// 输出图像并释放内存
// 输出
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
]]>
</programlisting>
Expand Down Expand Up @@ -106,9 +103,8 @@ $sy = imagesy($stamp);
// 以 50% 的透明度合并水印和图像
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
// 将图像保存到文件,并释放内存
// 将图像保存到文件
imagepng($im, 'photo_stamp.png');
imagedestroy($im);
?>
]]>
Expand Down
3 changes: 1 addition & 2 deletions reference/image/functions/image-type-to-extension.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 89ae180a851621c308f0ea4604ff2e919aa57a7f Maintainer: HonestQiao Status: ready -->
<!-- EN-Revision: 9960a09a5705102bf4dd0ce63e03d9ec716d0015 Maintainer: HonestQiao Status: ready -->
<!-- CREDITS: mowangjuanzi, Luffy -->
<refentry xml:id="function.image-type-to-extension" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -62,7 +62,6 @@ $im = imagecreatetruecolor(100, 100);
// 保存图像
imagepng($im, './test' . image_type_to_extension(IMAGETYPE_PNG));
imagedestroy($im);
?>
]]>
</programlisting>
Expand Down
3 changes: 1 addition & 2 deletions reference/image/functions/image2wbmp.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 593ea510e853ff034e03f78a4be0daa41661c9d4 Maintainer: dallas Status: ready -->
<!-- EN-Revision: 9960a09a5705102bf4dd0ce63e03d9ec716d0015 Maintainer: dallas Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.image2wbmp" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -75,7 +75,6 @@ $image = imagecreatefrompng($file);
header('Content-Type: ' . image_type_to_mime_type(IMAGETYPE_WBMP));
image2wbmp($image); // 直接输出流
imagedestroy($image);
?>
]]>
</programlisting>
Expand Down
11 changes: 5 additions & 6 deletions reference/image/functions/imagealphablending.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 593ea510e853ff034e03f78a4be0daa41661c9d4 Maintainer: HonestQiao Status: ready -->
<!-- EN-Revision: 9960a09a5705102bf4dd0ce63e03d9ec716d0015 Maintainer: HonestQiao Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.imagealphablending" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -71,20 +71,19 @@
<programlisting role="php">
<![CDATA[
<?php
// Create image
// 创建图像
$im = imagecreatetruecolor(100, 100);
// Set alphablending to on
// 设置 alphablending 为开启
imagealphablending($im, true);
// Draw a square
// 画正方形
imagefilledrectangle($im, 30, 30, 70, 70, imagecolorallocate($im, 255, 0, 0));
// Output
// 输出
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
]]>
</programlisting>
Expand Down
16 changes: 7 additions & 9 deletions reference/image/functions/imageantialias.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 593ea510e853ff034e03f78a4be0daa41661c9d4 Maintainer: HonestQiao Status: ready -->
<!-- EN-Revision: 9960a09a5705102bf4dd0ce63e03d9ec716d0015 Maintainer: HonestQiao Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.imageantialias" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -80,30 +80,28 @@
<programlisting role="php">
<![CDATA[
<?php
// Setup an anti-aliased image and a normal image
// 设置抗锯齿图像和普通图像
$aa = imagecreatetruecolor(400, 100);
$normal = imagecreatetruecolor(200, 100);
// Switch antialiasing on for one image
// 为图片启用抗锯齿功能
imageantialias($aa, true);
// Allocate colors
// 分配颜色
$red = imagecolorallocate($normal, 255, 0, 0);
$red_aa = imagecolorallocate($aa, 255, 0, 0);
// Draw two lines, one with AA enabled
// 绘制两条线,其中一条启用 AA
imageline($normal, 0, 0, 200, 100, $red);
imageline($aa, 0, 0, 200, 100, $red_aa);
// Merge the two images side by side for output (AA: left, Normal: Right)
// 将两幅图像并排合并输出(AA:左,Normal:右)
imagecopymerge($aa, $normal, 200, 0, 0, 0, 200, 100, 100);
// Output image
// 输出图像
header('Content-type: image/png');
imagepng($aa);
imagedestroy($aa);
imagedestroy($normal);
?>
]]>
</programlisting>
Expand Down
5 changes: 1 addition & 4 deletions reference/image/functions/imagearc.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 593ea510e853ff034e03f78a4be0daa41661c9d4 Maintainer: dallas Status: ready -->
<!-- EN-Revision: 9960a09a5705102bf4dd0ce63e03d9ec716d0015 Maintainer: dallas Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.imagearc" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -142,9 +142,6 @@ imagearc($img, 140, 75, 50, 50, 0, 360, $blue);
header("Content-type: image/png");
imagepng($img);
// 释放内存
imagedestroy($img);
?>
]]>
</programlisting>
Expand Down
15 changes: 6 additions & 9 deletions reference/image/functions/imagecolorallocatealpha.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 593ea510e853ff034e03f78a4be0daa41661c9d4 Maintainer: HonestQiao Status: ready -->
<!-- EN-Revision: 9960a09a5705102bf4dd0ce63e03d9ec716d0015 Maintainer: HonestQiao Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.imagecolorallocatealpha" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -124,7 +124,6 @@ header('Content-Type: image/png');
// 最后,输出结果
imagepng($image);
imagedestroy($image);
?>
]]>
</programlisting>
Expand All @@ -137,19 +136,17 @@ imagedestroy($image);
</mediaobject>
</example>
<example xml:id="imagecolorallocatealpha.example.convert">
<title>Convert typical alpha values for use with <function>imagecolorallocatealpha</function></title>
<title>转换典型的 alpha 值以供 <function>imagecolorallocatealpha</function> 使用</title>
<para>
Usually alpha values of <literal>0</literal> designate fully transparent pixels,
and the alpha channel has 8 bits. To convert such alpha values to be compatible
with <function>imagecolorallocatealpha</function>, some simple arithmetic is
sufficient:
通常,alpha 值为 <literal>0</literal> 表示完全透明的像素,alpha 通道有 8 位。要转换此类
alpha 值以与 <function>imagecolorallocatealpha</function> 兼容,只需进行一些简单的算术运算即可:
</para>
<programlisting role="php">
<![CDATA[
<?php
$alpha8 = 0; // fully transparent
$alpha8 = 0; // 完全透明
var_dump(127 - ($alpha8 >> 1));
$alpha8 = 255; // fully opaque
$alpha8 = 255; // 完全不透明
var_dump(127 - ($alpha8 >> 1));
?>
]]>
Expand Down
12 changes: 5 additions & 7 deletions reference/image/functions/imagecolorclosest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 593ea510e853ff034e03f78a4be0daa41661c9d4 Maintainer: dallas Status: ready -->
<!-- EN-Revision: 9960a09a5705102bf4dd0ce63e03d9ec716d0015 Maintainer: dallas Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.imagecolorclosest" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -83,20 +83,20 @@
<programlisting role="php">
<![CDATA[
<?php
// Start with an image and convert it to a palette-based image
// 从图像开始并将其转换为基于调色板的图像
$im = imagecreatefrompng('figures/imagecolorclosest.png');
imagetruecolortopalette($im, false, 255);
// Search colors (RGB)
// 搜索颜色(RGB
$colors = array(
array(254, 145, 154),
array(153, 145, 188),
array(153, 90, 145),
array(255, 137, 92)
);
// Loop through each search and find the closest color in the palette.
// Return the search number, the search RGB and the converted RGB match
// 循环执行每个搜索并找到调色板中最接近的颜色。
// 返回搜索编号、搜索 RGB 和转换后的 RGB 匹配项
foreach($colors as $id => $rgb)
{
$result = imagecolorclosest($im, $rgb[0], $rgb[1], $rgb[2]);
Expand All @@ -105,8 +105,6 @@ foreach($colors as $id => $rgb)
echo "#$id: Search ($rgb[0], $rgb[1], $rgb[2]); Closest match: $result.\n";
}
imagedestroy($im);
?>
]]>
</programlisting>
Expand Down
9 changes: 4 additions & 5 deletions reference/image/functions/imagetruecolortopalette.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 593ea510e853ff034e03f78a4be0daa41661c9d4 Maintainer: HonestQiao Status: ready -->
<!-- EN-Revision: 9960a09a5705102bf4dd0ce63e03d9ec716d0015 Maintainer: HonestQiao Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.imagetruecolortopalette" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -78,15 +78,14 @@
<programlisting role="php">
<![CDATA[
<?php
// Create a new true color image
// 创建新的真彩色图像
$im = imagecreatetruecolor(100, 100);
// Convert to palette-based with no dithering and 255 colors
// 转换为基于调色板的无抖动和 255 种颜色
imagetruecolortopalette($im, false, 255);
// Save the image
// 保存图像
imagepng($im, './paletteimage.png');
imagedestroy($im);
?>
]]>
</programlisting>
Expand Down
3 changes: 1 addition & 2 deletions reference/image/functions/imagettfbbox.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 593ea510e853ff034e03f78a4be0daa41661c9d4 Maintainer: dallas Status: ready -->
<!-- EN-Revision: 9960a09a5705102bf4dd0ce63e03d9ec716d0015 Maintainer: dallas Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.imagettfbbox" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -176,7 +176,6 @@ imagettftext($im, 10, 45, $x, $y, $black, $font, 'and Zend Engine ' . zend_versi
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
]]>
</programlisting>
Expand Down
19 changes: 9 additions & 10 deletions reference/image/functions/imagettftext.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 593ea510e853ff034e03f78a4be0daa41661c9d4 Maintainer: HonestQiao Status: ready -->
<!-- EN-Revision: 9960a09a5705102bf4dd0ce63e03d9ec716d0015 Maintainer: HonestQiao Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.imagettftext" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
Expand Down Expand Up @@ -143,32 +143,31 @@
<programlisting role="php">
<![CDATA[
<?php
// Set the content-type
// 设置 content-type
header('Content-Type: image/png');
// Create the image
// 创建图像
$im = imagecreatetruecolor(400, 30);
// Create some colors
// 创建一些颜色
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
// 要绘制的文本
$text = 'Testing...';
// Replace path by your own font path
// 用自己的字体路径替换路径
$font = 'arial.ttf';
// Add some shadow to the text
// 给文本添加一些阴影
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
// 添加文本
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
// 与 imagejpeg() 相比,使用 imagepng() 可产生更清晰的文本
imagepng($im);
imagedestroy($im);
?>
]]>
</programlisting>
Expand Down
11 changes: 1 addition & 10 deletions reference/image/functions/imagewbmp.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 593ea510e853ff034e03f78a4be0daa41661c9d4 Maintainer: dallas Status: ready -->
<!-- EN-Revision: 9960a09a5705102bf4dd0ce63e03d9ec716d0015 Maintainer: dallas Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.imagewbmp" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -91,9 +91,6 @@ header('Content-Type: image/vnd.wap.wbmp');
// 输出图像
imagewbmp($im);
// 释放内存
imagedestroy($im);
?>
]]>
</programlisting>
Expand All @@ -112,9 +109,6 @@ imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
// 保存图像
imagewbmp($im, 'simpletext.wbmp');
// 释放内存
imagedestroy($im);
?>
]]>
</programlisting>
Expand All @@ -139,9 +133,6 @@ header('Content-Type: image/vnd.wap.wbmp');
$foreground_color = imagecolorallocate($im, 255, 0, 0);
imagewbmp($im, NULL, $foreground_color);
// 释放内存
imagedestroy($im);
?>
]]>
</programlisting>
Expand Down
Loading

0 comments on commit 38cd583

Please sign in to comment.