473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

imagefilledpolygon() with a pattern

Good morning,

I would like to draw a polygon and then fill it with a pattern instead
of a solid colour.

Is there any functions available which will accomplish what I am
attempting or do I have to write my own function?

Thanks in advance

Albert

Jul 21 '05 #1
1 1456
By pure chance I stumbled across the imagesettile() method. This can be
used to fill a polygon (or any other shape) with a specific pattern.

So I wrote the following function to create a crosshash fill:

Expand|Select|Wrap|Line Numbers
  1. function imageCrossHashFill($image, $polygonPoints, $colour) {
  2. $r = hexdec(substr($colour, 0, 2));
  3. $g = hexdec(substr($colour, 2, 2));
  4. $b = hexdec(substr($colour, 4, 2));
  5.  
  6. $crossHash = imagecreate(20, 20);
  7. $bg2 = imagecolorallocate($crossHash, 255, 255, 255);
  8. $red2 = imagecolorallocate($crossHash, $r, $g, $b);
  9. imageline($crossHash, 0, 0, 20, 20, $red2);
  10. imageline($crossHash, 0, 10, 10, 20, $red2);
  11. imageline($crossHash, 10, 0, 20, 10, $red2);
  12. imageline($crossHash, 20, 0, 0, 20, $red2);
  13. imageline($crossHash, 10, 0, 0, 10, $red2);
  14. imageline($crossHash, 20, 10, 10, 20, $red2);
  15. imagecolortransparent($crossHash, $bg2);
  16.  
  17. imagesettile($image, $crossHash);
  18. imagefilledpolygon($image, $polygonPoints, count($polygonPoints) / 2,
  19. IMG_COLOR_TILED);
  20.  
  21. imagedestroy($crossHash);
  22. }
  23.  
You can fill the polygon with anything by changing the $crossHash
image.

Have a good day

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: gsv2com | last post by:
One of my weaknesses has always been pattern matching. Something I definitely need to study up on and maybe you guys can give me a pointer here. I'm looking to remove all of this code and just...
0
by: Andy Read | last post by:
Hello all, I have the requirement to produce source code that produces an object hierarchy. Example: Root | Folder 1
2
by: CV | last post by:
How can I match 'n' number of neighbouring words of a pattern using regular expressions? For example, suppose I am looking for the pattern "length xyz cm" in some text. where xyz is a number -...
11
by: FluffyCat | last post by:
In Febraury - April of 2002 I put together in Java examples of all 23 of the classic "Gang Of Four" design patterns for my website. Partly I wanted to get a better understanding of those patterns....
1
by: Sea Sharper | last post by:
Hi, C#, from a FileSystemWatcher I would like to catch all files with a *.* filter but then inside the event handler compare against a list of wildcards (eg '*.abc;*.def') Is there anywhere...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
11
by: td0g03 | last post by:
Hello, I just have a few questions. The first one be how would you print a pattern. I could use the if else, but I remember my teacher talking about something like for(i=1;i<=size;i) ...
1
by: halekio | last post by:
Hi all, Please bear with me as I've only started programming in C# 2 weeks ago and this is my first contact with OOP. I ran into a situation where I needed to catch an event in an object that...
19
by: konrad Krupa | last post by:
I'm not expert in Pattern Matching and it would take me a while to come up with the syntax for what I'm trying to do. I hope there are some experts that can help me. I'm trying to match...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.