/ Published in: PHP
Save this script on your localhost and run it whenever you need to generate a "hamburger icon" of a specific size and color. Just tell it the dimensions and bar color and it will output a mathematically perfect hamburger icon as a transparent PNG, which you can just download.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // Enable robust error reporting to catch errors // Generate an image if the form has been submitted // $side is the width and height of the resulting image // $color is a hexadecimal color (000000 to FFFFFF) $color = $_GET['color']; // If the $color begins with a # sign, strip it off // Split the color into the hex value for red, green, and blue // Convert the hexadecimal strings to decimal numbers (00=00, FF=255) // Create the canvas // Preserve transparency // Fill it with a transparent background // Allocate the bar color // Draw 3 rectangles on the canvas from (x1, x2) to (y1, y2) and fill // them with the bar color $x1 = $side/7; $x2 = $side-$x1; for ($y1 = $x1; $y1 < $x2; $y1 += $x1*2) { } // Output the PNG if no errors were printed during this process } // Terminate exit; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Hamburger Icon Generator</title> </head> <body> <h1>Hamburger Icon Generator</h1> <form method="get" target="_blank"> <p><label>Size <input type="number" name="side" min="7" max="700" step="7" value="49" onchange="document.getElementById('side').innerHTML = this.value;">×<span id="side">49</span> (must be a multiple of 7)</label></p> <p><label>Bar Color #<input type="text" name="color" value="000000"> (hex values only)</label></p> <p><input type="submit" value="Generate"></p> </form> </body> </html>