search
HomeBackend DevelopmentPHP Tutorial PHP画图的一些疑义

PHP画图的一些疑问


PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$src621 = imagecreate(200,200); 
$yellow = imagecolorallocate($src621, 255, 255, 0);
$red = imagecolorallocate($src621, 255, 0, 0);
$green = imagecolorallocate($src621, 0, 255, 0);
imagerectangle($src621, 100, 50, 150, 150, $green);
imagefill($src621, 0, 0, $red);
header("Content-Type: image/png");
imagepng ($src621);
imagedestroy($src621);



结果:


疑问一、yellow颜色是怎么被画上去的?
疑问二、imagefill函数的中间2个参数有什么用?(自己测试发现,改变不起作用,如果改变大了,就没有填充颜色)

求牛人解答。谢谢!!

------解决方案--------------------
注: 第一次对 imagecolorallocate() 的调用会填充背景色。 
//imagefill($src621, 0, 0, $red);//注释掉这句你就看出来了
imagefile是点区域填充,左上角是(0,0)
为黄色,意思把所有红色(选区)填充为$red,像ps里的油漆筒
这个选区是关键,为啥里面的红色未被填充,那是因为
imagerectangle($src621, 100, 50, 150, 150, $green);//矩形的边框为绿色
这个green色隔开了红色,也就是里面给与外面红不在一个选区
不信你再改一下这句测试
imagefill($src621, 101, 51, $red);//这样点跑矩形里面了,选中的是矩形里面的红区域


------解决方案--------------------
对于 imagecreate 创建的资源,第一个创建的颜色为背景色
imagefill函数的中间2个参数是充填的起点坐标(原点),从这点出发直至边界,所有可到达的位置并且颜色与原点相同的都设为指定色

用于你在 imagefill 之前换了一个空心矩形(imagerectangle)所以该矩形的边缘是作为边界的
不被充填,自然也就露出背景了
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
src和href是什么意思src和href是什么意思Aug 16, 2023 pm 05:00 PM

src和href分别是,1、src是source的缩写,用于指定外部资源的路径,通常用于嵌入外部文件,比如图片、音频、视频等,src属性一般用在img、script、iframe等标签上;2、href是hypertext reference的缩写,用于指定超链接的目标资源的路径,通常用于链接到外部文档或其他页面,href属性一般用在a、link等标签上。

src属性和href属性在功能和用法上的区别有哪些?src属性和href属性在功能和用法上的区别有哪些?Dec 28, 2023 am 08:20 AM

src属性和href属性是在HTML中常用的属性,用于加载外部资源。虽然它们有相似的目的,但在使用和用途上有一些不同。src属性:src属性用于指定要在文档中嵌入的外部资源,主要用于在HTML文档中引入外部脚本文件和媒体文件。它可以用于以下几种情况:引入外部JavaScript文件:通过src属性,将外部的JavaScript文件链接到HTML页面。

href和src发送的什么请求href和src发送的什么请求Aug 17, 2023 pm 02:20 PM

href和src发送的get请求。详细说明:1、href属性,用于指定链接的目标资源,引用外部样式表会发送GET请求来获取CSS文件,引用文档会发送GET请求来获取指定的HTML文件,引用图像时它会发送GET请求来获取指定的图像文件;2、src属性,用于指定嵌入资源的URL,引用图像时会发送GET请求来获取指定的图像文件,引用音频它会发送一个GET请求来获取指定的音频文件等等。

了解src和href的不同点的重要细节!了解src和href的不同点的重要细节!Jan 06, 2024 am 09:11 AM

src和href的差异,你不可不知的细节!在编写HTML页面时,我们经常会遇到src和href这两个属性。它们都用于引用外部资源,比如脚本文件、样式文件或者图片。虽然它们的用途相似,但它们在具体的用法和细节上却存在一些差异。首先,src(source)属性主要用于嵌入外部资源,比如图片或者脚本。它是用于指定资源的地址,并将其内容嵌入到当前文档中。而href(

src和href的区别究竟是什么?快速了解!src和href的区别究竟是什么?快速了解!Jan 06, 2024 pm 09:09 PM

src和href的区别究竟是什么?快速了解!在网页开发过程中,src和href是两个经常使用的属性。尽管它们看起来类似,但实际上有着不同的用途和适用场景。在本文中,我们将深入探讨src和href的区别,并通过具体的代码示例来解释它们。在HTML中,src是用于指定要嵌入或引用的外部资源的属性,它通常用于引用图像、音频、视频或脚本文件。与此不同,href是超链

什么是src属性和href属性?它们有什么区别?什么是src属性和href属性?它们有什么区别?Dec 28, 2023 pm 03:18 PM

什么是src属性和href属性?它们有什么区别?在HTML中,src属性和href属性是两个常用的属性,用于引用外部资源。虽然它们在功能上有些相似,但在用法和引用资源类型上有一些区别。首先,让我们来看一下src属性。src是source的缩写,主要用于指定嵌入/引用外部资源的地址。它可以被应用于一些标签,如

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.