- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set the tile image for filling using imagesettile() function in PHP?
imagesettle() is an inbuilt function in PHP that is used to set the tile image for filling. It sets the image to be used by all-region filling functions like imagefill() and imagefilledpolygon() when filling with a special color IMG_COLOR_TILED.
We can say that a tile is an image that is used to fill an area with a repeated pattern. We can use any GD image as a tile.
Syntax
bool imagesettile($image, $tile)
Parameters
imagesettile() takes two parameters: $image and $tile.
$image − Holds a GD image.
$tile − The $tile parameter is used to set the image resource as a tile.
Return Values
imagesettile() returns True on success and False on failure.
Example 1
<?php // Load the PNG image by using imagecreatefrompng() function. $image = imagecreatefrompng('C:\xampp\htdocs\Images\img27.png'); // Create an image of 700x300 size $img = imagecreatetruecolor(700, 300); // Set the image tile imagesettile($img, $image); // Make the image repeat and IMG_COLOR_TILED is used imagefilledrectangle($img, 0, 0, 300, 199, IMG_COLOR_TILED); // Output an image to the browser header('Content-Type: image/png'); imagepng($img); imagedestroy($img); imagedestroy($image); ?>
Input Image
Output Image
Example 2
<?php // Load the PNG image by using imagecreatefrompng() function. $image = imagecreatefrompng('C:\xampp\htdocs\Images\img27.png'); // Create an image of 700x400 size $img = imagecreatetruecolor(700, 400); // Set the image tile imagesettile($img, $image); // Make the image repeat, IMG_COLOR_TILED is used imagefilledrectangle($img, 0, 0, 390, 370, IMG_COLOR_TILED); // Output an image to the browser header('Content-Type: image/png'); imagepng($img); imagedestroy($img); imagedestroy($image); ?>
Output
Advertisements