Skip to content

WebilyBE/Dynamic-Placeholder-Image-Generator-Script-in-PHP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

Dynamic Placeholder Image

This PHP script generates an image with the specified width, height, and colors. Let's delve into the specifics:

  1. 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).

  2. 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.

  3. 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.

  4. 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.

  5. 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. Webily

  • 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. Webily

  • placeholder.php?w=1000&h=550: This produces a 1000x550 pixel image with default background and text colors. Webily

About

This code is a PHP script that generates an image with the specified width, height, and colors.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages