Site Builder
Editing:
wordpress-asset-generator.php
writable 0666
<?php /* ------------------------------------------------------------------ Quick “WordPress‑asset generator” for Promptinator Requirements: PHP ≥ 7.4 + GD extension enabled ------------------------------------------------------------------ */ $bg = $_POST['bg'] ?? '#5c3bff'; $headline= trim($_POST['txt'] ?? 'Promptinator'); $font = __DIR__ . '/OpenSans-Bold.ttf'; // any TTF on your server function hex2rgb(string $hex): array { $hex = ltrim($hex, '#'); if (strlen($hex) === 3) $hex = $hex[0].$hex[0].$hex[1].$hex[1].$hex[2].$hex[2]; return [hexdec($hex[0].$hex[1]), hexdec($hex[2].$hex[3]), hexdec($hex[4].$hex[5])]; } function make_image(int $w, int $h, string $bg, callable $draw, string $file) { [$r,$g,$b] = hex2rgb($bg); $im = imagecreatetruecolor($w, $h); $col= imagecolorallocate($im,$r,$g,$b); imagefill($im, 0, 0, $col); $draw($im); imagepng($im, $file); imagedestroy($im); } /* ------------------------------------------------------------------ Generate when the form is submitted ------------------------------------------------------------------ */ if ($_SERVER['REQUEST_METHOD'] === 'POST' && extension_loaded('gd')) { /* 1. Banner 772 × 250 */ make_image(772, 250, $bg, function($im) use ($headline,$font) { $white = imagecolorallocate($im,255,255,255); $size = 58; // adjust font size $bbox = imagettfbbox($size, 0, $font, $headline); $txtW = $bbox[2] - $bbox[0]; $txtH = $bbox[1] - $bbox[7]; imagettftext($im, $size, 0, (imagesx($im)-$txtW)/2, (imagesy($im)+$txtH)/2, $white, $font, $headline); }, 'banner-772x250.png'); /* 2. Icon 256 × 256 (circle) */ make_image(256, 256, 'transparent', function($im) use ($bg,$headline,$font) { imagesavealpha($im, true); $transparent = imagecolorallocatealpha($im,0,0,0,127); imagefill($im, 0, 0, $transparent); [$r,$g,$b] = hex2rgb($bg); $circleCol = imagecolorallocate($im,$r,$g,$b); imagefilledellipse($im,128,128,256,256,$circleCol); $white = imagecolorallocate($im,255,255,255); $letter= mb_substr($headline,0,1); $size = 120; $bbox = imagettfbbox($size, 0, $font, $letter); $txtW = $bbox[2]-$bbox[0]; $txtH = $bbox[1]-$bbox[7]; imagettftext($im,$size,0,(256-$txtW)/2,(256+$txtH)/2,$white,$font,$letter); }, 'icon-256x256.png'); $generated = true; } ?> <!doctype html><html><head><meta charset="utf-8"><title>Promptinator Asset Maker</title> <style>body{font-family:Arial,Helvetica,sans-serif;margin:40px;}label{display:block;margin:.8em 0}</style> </head><body> <h1>Promptinator Asset Maker</h1> <form method="post"> <label>Background color: <input type="color" name="bg" value="<?=htmlspecialchars($bg)?>"> </label> <label>Text on banner / icon: <input type="text" name="txt" value="<?=htmlspecialchars($headline)?>" style="width:300px"> </label> <button>Generate PNGs</button> </form> <?php if (!extension_loaded('gd')): ?> <p style="color:red;">Error: PHP GD extension is not enabled.</p> <?php elseif (!file_exists($font)): ?> <p style="color:red;">Error: font file not found (expected <code><?=$font?></code>).</p> <?php elseif (!empty($generated)): ?> <h2>Preview</h2> <p><strong>Banner 772 × 250</strong><br> <img src="banner-772x250.png?<?=time()?>" alt="banner"></p> <p><strong>Icon 256 × 256</strong><br> <img src="icon-256x256.png?<?=time()?>" alt="icon" style="border-radius:10px;"></p> <p> <a href="banner-772x250.png" download>Download banner‑772x250.png</a> · <a href="icon-256x256.png" download>Download icon‑256x256.png</a> </p> <?php endif; ?> <p style="margin-top:2em;font-size:.9em;color:#666;"> *Images are written to the same folder as this script. *Requires <code>GD</code> and a TrueType font (change the path near the top if needed). </p> </body></html>
Save changes
Create folder
writable 0777
Create
Cancel