This PHP script generates an image with the specified width, height, and colors. Let's delve into the specifics:
-
Width and Height: The script retrieves the width and height from the _GET parameters (w and h). If not provided, default values of 1000 are used. They are then checked to ensure they stay within certain limits (maxWidth and maxHeight).
-
Color: The background color is also fetched from the _GET parameters (color). If not specified, the default color "#ccc" is used. The script checks if the color is in the correct hexadecimal format and converts it to RGB.
-
Text Color: Optionally, a text color (textColor) can be provided in the _GET parameters. If not specified, the text color is automatically determined based on the brightness of the background color.
-
Adding Text: The script adds text to the image with dimensions matching the image itself. The size and position of the text are calculated based on the image's size. The text font is adjusted to fit the image size.
-
Generating Image: Finally, the image is generated using PHP's GD Library and output as a PNG file.
The script also takes care of some HTTP headers to manage caching and the file format of the generated image. Here are some examples of how you could use this script:
-
placeholder.php?w=1000&h=550&color=667F99&textColor=FFFFFF: This generates a 1000x550 pixel image with a background color of #667F99 and white text. -
placeholder.php?w=1000&h=550&color=667F99: This creates a 1000x550 pixel image with a background color of #5D9B9B. The text color is automatically determined based on the brightness of the background color. -
placeholder.php?w=1000&h=550: This produces a 1000x550 pixel image with default background and text colors.