无需言 做自己 业 ,精于勤 荒于嬉.
- GD 和图像处理 函数 imageftbbox 给出一个使用 FreeType 2 字体的文本框
-
发表日期:2021-07-01 08:55:59 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php // Create a 300x150 image$im = imagecreatetruecolor(300, 150); $black = imagecolorallocate($im, 0, 0, 0); $white = imagecolorallocate($im, 255, 255, 255); // Set the background to be whiteimagefilledrectangle($im, 0, 0, 299, 299, $white); // Path to our font file$font = './arial.ttf'; // First we create our bounding box$bbox = imageftbbox(10, 0, $font, 'The PHP Documentation Group'); // This is our cordinates for X and Y$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 5; $y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5; imagefttext($im, 10, 0, $x, $y, $black, $font, 'The PHP Documentation Group'); // Output to browserheader('Content-Type: image/png'); imagepng($im); imagedestroy($im); ?>
- GD 和图像处理 函数 imagegammacorrect 对 GD 图像应用 gamma 修正
-
发表日期:2021-07-01 08:55:59 | 来源: | 分类:GD 和图像处理 函数
-
imagegammacorrect
(PHP 4, PHP 5, PHP 7, PHP 8)
imagegammacorrect — 对 GD 图像应用 gamma 修正
说明
imagegammacorrect(resource$image
, float$inputgamma
, float$outputgamma
): boolimagegammacorrect() 函数用给定的输入 gamma 值
inputgamma
和输出 gamma 值outputgamma
对一幅 GD 图像流(image
)应用 gamma 修正。
- GD 和图像处理 函数 imagegd2 将 GD2 图像输出到浏览器或文件
-
发表日期:2021-07-01 08:55:59 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php // Create a blank image and add some text$im = imagecreatetruecolor(120, 20); $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 1, 5, 5, "A Simple Text String", $text_color); // Output the imageimagegd2($im); // Free up memoryimagedestroy($im); ?>
示例2
<?php // Create a blank image and add some text$im = imagecreatetruecolor(120, 20); $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 1, 5, 5, "A Simple Text String", $text_color); // Save the gd2 image// The file format for GD2 images is .gd2, see http://www.libgd.org/GdFileFormatsimagegd2($im, 'simple.gd2'); // Free up memoryimagedestroy($im); ?>
- GD 和图像处理 函数 imagecreatefrombmp 由文件或 URL 创建一个新图象。
-
发表日期:2021-07-01 08:55:58 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php // Load the BMP file$im = imagecreatefrombmp('./example.bmp'); // Convert it to a PNG file with default settingsimagepng($im, './example.png'); imagedestroy($im); ?>
- GD 和图像处理 函数 imagecopyresized 拷贝部分图像并调整大小
-
发表日期:2021-07-01 08:55:58 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php // File and new size$filename = 'test.jpg'; $percent = 0.5; // Content typeheader('Content-Type: image/jpeg'); // Get new sizeslist($width, $height) = getimagesize($filename); $newwidth = $width * $percent; $newheight = $height * $percent; // Load$thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefromjpeg($filename); // Resizeimagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // Outputimagejpeg($thumb); ?>
- GD 和图像处理 函数 imagecreate 新建一个基于调色板的图像
-
发表日期:2021-07-01 08:55:58 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php header("Content-type: image/png"); $im = @imagecreate(100, 50) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 255, 255, 255); $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 1, 5, 5, "A Simple Text String", $text_color); imagepng($im); imagedestroy($im); ?>
- GD 和图像处理 函数 imagecreatefromgd2 从 GD2 文件或 URL 新建一图像
-
发表日期:2021-07-01 08:55:58 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php // 加载 gd2 图像$im = imagecreatefromgd2('./test.gd2'); // 在图像上应用效果。// 在这个例子中,如果版本为 PHP5+ 则反转图像颜色if(function_exists('imagefilter')){ imagefilter($im, IMG_FILTER_NEGATE); } // 保存图像imagegd2($im, './test_updated.gd2'); imagedestroy($im); ?>
- GD 和图像处理 函数 imagecreatefromgd2part 从给定的 GD2 文件或 URL 中的部分新建一图像
-
发表日期:2021-07-01 08:55:58 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php // For this example we need the image size before$image = getimagesize('./test.gd2'); // Create the image instance now we got the image // sizes$im = imagecreatefromgd2part('./test.gd2', 4, 4, ($image[0] / 2) - 6, ($image[1] / 2) - 6); // Do an image operation, in this case we emboss the // image if PHP 5+if(function_exists('imagefilter')){ imagefilter($im, IMG_FILTER_EMBOSS); } // Save optimized imageimagegd2($im, './test_emboss.gd2'); imagedestroy($im); ?>
- GD 和图像处理 函数 imagecreatefromgd 从 GD 文件或 URL 新建一图像
-
发表日期:2021-07-01 08:55:58 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php // Load the gd image$im = @imagecreatefromgd('./test.gd'); // Test if the image was loadedif(!is_resource($im)){ die('Unable to load gd image!'); } // Do image operations here// Save the imageimagegd($im, './test_updated.gd'); imagedestroy($im); ?>
- GD 和图像处理 函数 imagecreatefromgif 由文件或 URL 创建一个新图象。
-
发表日期:2021-07-01 08:55:58 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php function LoadGif($imgname){ /* Attempt to open */ $im = @imagecreatefromgif($imgname); /* See if it failed */ if(!$im) { /* Create a blank image */ $im = imagecreatetruecolor (150, 30); $bgc = imagecolorallocate ($im, 255, 255, 255); $tc = imagecolorallocate ($im, 0, 0, 0); imagefilledrectangle ($im, 0, 0, 150, 30, $bgc); /* Output an error message */ imagestring ($im, 1, 5, 5, 'Error loading ' . $imgname, $tc); } return $im; } header('Content-Type: image/gif'); $img = LoadGif('bogus.image'); imagegif($img); imagedestroy($img); ?>
- GD 和图像处理 函数 imagecreatefromjpeg 由文件或 URL 创建一个新图象。
-
发表日期:2021-07-01 08:55:58 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php function LoadJpeg($imgname){ /* 尝试打开 */ $im = @imagecreatefromjpeg($imgname); /* See if it failed */ if(!$im) { /* Create a black image */ $im = imagecreatetruecolor(150, 30); $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 150, 30, $bgc); /* Output an error message */ imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc); } return $im; } header('Content-Type: image/jpeg'); $img = LoadJpeg('bogus.image'); imagejpeg($img); imagedestroy($img); ?>
- GD 和图像处理 函数 imagecreatefrompng 由文件或 URL 创建一个新图象。
-
发表日期:2021-07-01 08:55:58 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php function LoadPNG($imgname){ /* Attempt to open */ $im = @imagecreatefrompng($imgname); /* See if it failed */ if(!$im) { /* Create a blank image */ $im = imagecreatetruecolor(150, 30); $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 150, 30, $bgc); /* Output an error message */ imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc); } return $im; } header('Content-Type: image/png'); $img = LoadPNG('bogus.image'); imagepng($img); imagedestroy($img); ?>
- GD 和图像处理 函数 imagecreatefromstring 从字符串中的图像流新建一图像
-
发表日期:2021-07-01 08:55:58 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php $data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl' . 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr' . 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r' . '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg=='; $data = base64_decode($data); $im = imagecreatefromstring($data); if ($im !== false) { header('Content-Type: image/png'); imagepng($im); imagedestroy($im); } else { echo 'An error occurred.'; } ?>
- GD 和图像处理 函数 imagecopyresampled 重采样拷贝部分图像并调整大小
-
发表日期:2021-07-01 08:55:58 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php // 这个文件$filename = 'test.jpg'; $percent = 0.5; // 内容类型header('Content-Type: image/jpeg'); // 获取新的尺寸list($width, $height) = getimagesize($filename); $new_width = $width * $percent; $new_height = $height * $percent; // 重新取样$image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // 输出imagejpeg($image_p, null, 100); ?>
示例2
<?php // 源文件$filename = 'test.jpg'; // 设置最大宽高$width = 200; $height = 200; // Content typeheader('Content-Type: image/jpeg'); // 获取新尺寸list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // 重新取样$image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // 输出imagejpeg($image_p, null, 100); ?>
- GD 和图像处理 函数 imagecreatefromwebp 由文件或 URL 创建一个新图象。
-
发表日期:2021-07-01 08:55:58 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php // 加载 WebP 文件$im = imagecreatefromwebp('./example.webp'); // 以 100% 的质量转换成 jpeg 格式imagejpeg($im, './example.jpeg', 100); imagedestroy($im); ?>
- GD 和图像处理 函数 imagecreatefromxbm 由文件或 URL 创建一个新图象。
-
发表日期:2021-07-01 08:55:58 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php // Load the xbm file$xbm = imagecreatefromxbm('./example.xbm'); // Convert it to a png fileimagepng($xbm, './example.png'); imagedestroy($xbm); ?>
- GD 和图像处理 函数 imagecrop Crop an image to the given rectangle
-
发表日期:2021-07-01 08:55:58 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php $im = imagecreatefrompng('example.png'); $size = min(imagesx($im), imagesy($im)); $im2 = imagecrop($im, ['x' => 0, 'y' => 0, 'width' => $size, 'height' => $size]); if ($im2 !== FALSE) { imagepng($im2, 'example-cropped.png'); imagedestroy($im2); } imagedestroy($im); ?>
- GD 和图像处理 函数 imagecropauto Crop an image automatically using one of the available modes
-
发表日期:2021-07-01 08:55:58 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php $cropped = imagecropauto($im, IMG_CROP_DEFAULT); if ($cropped !== false) { // in case a new image object was returned imagedestroy($im); // we destroy the original image $im = $cropped; // and assign the cropped image to $im} ?>
- GD 和图像处理 函数 imagecreatefromwbmp 由文件或 URL 创建一个新图象。
-
发表日期:2021-07-01 08:55:58 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?php function LoadWBMP($imgname){ /* Attempt to open */ $im = @imagecreatefromwbmp($imgname); /* See if it failed */ if(!$im) { /* Create a blank image */ $im = imagecreatetruecolor(150, 30); $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 150, 30, $bgc); /* Output an error message */ imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc); } return $im; } header('Content-Type: image/vnd.wap.wbmp'); $img = LoadWBMP('bogus.image'); imagewbmp($img); imagedestroy($img); ?>
- GD 和图像处理 函数 imagecolorclosestalpha 取得与指定的颜色加透明度最接近的颜色
-
发表日期:2021-07-01 08:55:57 | 来源: | 分类:GD 和图像处理 函数
-
示例1
<?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)$colors = array( array(254, 145, 154, 50), array(153, 145, 188, 127), array(153, 90, 145, 0), array(255, 137, 92, 84)); // Loop through each search and find the closest color in the palette.// Return the search number, the search RGB and the converted RGB matchforeach($colors as $id => $rgb){ $result = imagecolorclosestalpha($im, $rgb[0], $rgb[1], $rgb[2], $rgb[3]); $result = imagecolorsforindex($im, $result); $result = "({ $result['red']} , { $result['green']} , { $result['blue']} , { $result['alpha']} )"; echo "#$id: Search ($rgb[0], $rgb[1], $rgb[2], $rgb[3]); Closest match: $result.\n"; } imagedestroy($im); ?>
- 前端开发(1)
- 数据库(0)
- PHP(0)
- PHP杂项(34)
- PHP基础-李炎恢系列课程(20)
- 中文函数手册(0)
- 错误处理 函数(13)
- OPcache 函数(6)
- PHP 选项/信息 函数(54)
- Zip 函数(10)
- Hash 函数(15)
- OpenSSL 函数(63)
- Date/Time 函数(51)
- 目录函数(9)
- Fileinfo 函数(6)
- iconv 函数(11)
- 文件系统函数(81)
- 多字节字符串 函数(57)
- GD 和图像处理 函数(114)
- 可交换图像信息(5)
- Math 函数(50)
- 程序执行函数(11)
- PCNTL 函数(23)
- JSON 函数(4)
- SPL 函数(15)
- URL 函数(10)
- cURL 函数(32)
- 网络 函数(33)
- FTP 函数(36)
- Session 函数(23)
- PCRE 函数(11)
- PCRE 正则语法(19)
- 数组 函数(81)
- 类/对象 函数(18)
- 函数处理 函数(13)
- 变量处理 函数(37)
- SimpleXML 函数(3)
- 杂项 函数(31)
- 字符串 函数(101)
- JAVA(0)
- Android(0)
- Linux(0)
- 其他(0)