This section provides a suite of functions to retrieve the colors used in a country's flag in various formats. You can explore the various formats available for representing flag colors. We offer a comprehensive set of color data for each flag, making it easy for you to display them in the format that best suits your project.
You can explore the various formats available for representing flag colors. We offer a comprehensive set of color data for each flag, making it easy for you to display them in the format that best suits your project.
Each color is represented in different formats, including:
{
"name": ["Blue", "Yellow", "Red"],
"web_name": ["blue", "yellow", "red"],
"hex": ["#0032A0", "#FEDF00", "#D1001F"],
"rgb": ["0,50,160", "254,223,0", "209,0,31"],
"cmyk": ["100,69,0,37", "0,12,100,0", "0,100,85,18"],
"hsl": ["224,100%,31%", "52,100%,50%", "350,100%,41%"],
"hsv": ["224,100%,63%", "52,100%,100%", "350,100%,82%"],
"pantone": ["Pantone 286 C", "Pantone 116 C", "Pantone 199 C"],
"contrast": ["#FFFFFF", "#000000", "#FFFFFF"]
}
Provides an array of the country's flag colors by name. This function returns the same value as getFlagColorsName().
::: code-group
$country = Country::inRandomOrder()->first();
$country->getFlagColors(); // [!code focus]
array:3 [▼
0 => "Red"
1 => "Green"
2 => "Yellow"
]
:::
Returns an array of the country's flag colors as color names. Use this function to obtain the names of the colors used in the country's flag.
::: code-group
$country = Country::inRandomOrder()->first();
$country->getFlagColorsName(); // [!code focus]
array:3 [▼
0 => "Red"
1 => "Green"
2 => "Yellow"
]
:::
Returns an array of the country's flag colors as web-safe color codes. Use this to get the colors in web-safe hexadecimal format, suitable for web design.
::: code-group
$country = Country::whereIso('pt')->first();
$country->getFlagColorsWeb(); // [!code focus]
array:3 [▼
0 => "red"
1 => "green"
2 => "yellow"
]
:::
Provides an array of the country's flag colors as contrast colors. This can be used to obtain colors that provide good contrast with the flag's colors, useful for overlays or text.
::: code-group
$country = Country::whereIso('PT')->first();
$country->getFlagColorsContrast(); // [!code focus]
array:3 [▼
0 => "#FFFFFF"
1 => "#FFFFFF"
2 => "#000000"
]
:::
Returns an array of the country's flag colors as hexadecimal color codes. This function gives you the colors in standard hex format, commonly used in web development and design.
::: code-group
$country = Country::whereIsoAlpha2('pt')->first();
$country->getFlagColorsHex(); // [!code focus]
array:3 [▼
0 => "#FF0000"
1 => "#006600"
2 => "#FFD700"
]
:::
Provides an array of the country's flag colors as RGB color codes. Use this to get the colors in Red-Green-Blue (RGB) format, suitable for various graphics applications.
::: code-group
$country = Country::whereIsoAlpha3('PRT')->first();
$country->getFlagColorsRgb(); // [!code focus]
array:3 [▼
0 => "255,0,0"
1 => "0,102,0"
2 => "255,215,0"
]
:::
Returns an array of the country's flag colors as CMYK color codes. This is useful for obtaining the colors in Cyan-Magenta-Yellow-Key (Black) format, commonly used in printing.
::: code-group
$country = Country::whereIsoNumeric(620)->first();
$country->getFlagColorsCmyk(); // [!code focus]
array:3 [▼
0 => "0,100,100,0"
1 => "100,0,100,60"
2 => "0,16,100,0"
]
:::
Provides an array of the country's flag colors as HSL color codes. Use this function to get the colors in Hue-Saturation-Lightness format.
::: code-group
$country = Country::whereGeoname(2264397)->first();
$country->getFlagColorsHsl(); // [!code focus]
array:3 [▼
0 => "0°,100%,50%"
1 => "120°,100%,20%"
2 => "51°,100%,50%"
]
:::
Returns an array of the country's flag colors as HSV color codes. This function gives the colors in Hue-Saturation-Value format.
::: code-group
$country = Country::whereOficialName('Portuguese Republic')->first();
$country->getFlagColorsHsv(); // [!code focus]
array:3 [▼
0 => "0°,100%,100%"
1 => "120°,100%,40%"
2 => "51°,100%,100%"
]
:::
Provides an array of the country's flag colors as Pantone color codes. Use this to obtain the Pantone Matching System codes for the flag's colors, useful for professional printing and design.
::: code-group
$country = Country::whereUid('01J9VCYGFSK2Z6G803C3GECMXM')->first();
$country->getFlagColorsPantone(); // [!code focus]
array:3 [▼
0 => "Red 032 C"
1 => "349 C"
2 => "116 C"
]
:::
This section offers handy helper functions to easily incorporate country flag colors into your web projects. Use them to create gradients, stripes, or borders with flag colors, adding a national touch to your websites, applications, or data visualizations!
These output helpers make it effortless to bring dynamic and colorful elements to your project, all while celebrating the unique palettes of different countries' flags!
Generates a CSS linear gradient using the country's flag colors. You can specify the direction of the gradient top, bottom, left, right, or even random for a customized background effect.
::: info
You can also choose the direction of the gradient by selecting from options like top, bottom, left, right, or even let the function pick a random direction for you!
:::
->getFlagGradient(string $startsOn = null)
::: code-group
$country = Country::whereIsoAlpha3('PRT')->first();
$country->getFlagGradient(); // [!code focus]
background: linear-gradient(90deg, #FF0000, #006600, #FFD700);
:::
::: details Click me to view code example
::: code-group
<div class="card">
<h3>{{ $country->name }}</h3>
<p>Here is a card with a gradient background using the flag colors.</p>
</div>
<style>
.card {
width: 300px;
height: 150px;
border-radius: 10px;
padding: 20px;
color: Black;
text-align: center;
font-family: Arial, sans-serif;
{!! $country->getFlagGradient(); !!}
/* background: linear-gradient(90deg, #FF0000, #FFFFFF, #0000FF); */
}
</style>
:::
::: details Click me to view example
:::
Creates a CSS linear gradient that combines the flag colors of two countries. This is great for representing partnerships, comparisons, or any scenario involving two nations.
::: info
You can also choose the direction of the gradient by selecting from options like top, bottom, left, right, or even let the function pick a random direction for you!
:::
->getCombinedFlagGradient(Country $otherCountry, string $startsOn = null)
::: code-group
$country = Country::whereIsoAlpha3('PRT')->first();
$country2 = Country::inRandomOrder()->first();
$country->getCombinedFlagGradient(otherCountry: $country2); // [!code focus]
background: linear-gradient(90deg, #FF0000, #006600, #FFD700, #CE1126, #0072C6, #FFFFFF, #FFD100, #000000);
:::
Generates a CSS linear gradient that displays the flag's colors in equal-width stripes. You can choose between horizontal or vertical orientation to best fit your design needs.
::: info
You can also choose the direction of the gradient by selecting from options like horizontal, vertical!
:::
->getFlagStripes(string $direction = 'horizontal')
::: code-group
$country = Country::whereIso('PRT')->first();
$country->getFlagStripes(); // [!code focus]
background: linear-gradient(to right, #FF0000 33.333333333333%, #006600 33.333333333333%, #FFD700 33.333333333333%);
:::
Produces a CSS string that applies the flag's colors to the borders of an element. Each side of the border can be a different color from the flag, adding a vibrant outline to your elements.
->getFlagBorders()
::: code-group
$country = Country::whereIso('PT')->first();
$country->getFlagBorders(); // [!code focus]
border-top: 5px solid #FF0000; border-right: 5px solid #006600; border-bottom: 5px solid #FFD700;
:::
How can I help you explore Laravel packages today?