') !== false) { $error_message = "Error: Angle brackets are not allowed in the prompt. Please use square brackets [lora-name:weight] for LORAs."; } // Only proceed if there's no error elseif (!empty($prompt)) { // Process the prompt to handle LORA syntax $processed_prompt = preg_replace('/\[([\w\s\-]+?):([\d\.]+)\]/', '', $prompt); $data = array( 'prompt' => $processed_prompt, 'steps' => $steps, 'width' => $width, 'height' => $height, 'cfg_scale' => $cfg_scale, 'sampler_name' => $sampler, 'override_settings' => new stdClass(), 'override_settings_restore_afterwards' => true ); // Replace 127.0.0.1 with your Stable diffusion server's IP if running externally $ch = curl_init('http://127.0.0.1:7860/sdapi/v1/txt2img'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); $result = curl_exec($ch); if (curl_errno($ch)) { $response = 'Error: ' . curl_error($ch); } else { $decoded = json_decode($result, true); if (isset($decoded['images'][0])) { $image_data = base64_decode($decoded['images'][0]); // Save original PNG temporarily $temp_png = 'temp_' . time() . '_' . bin2hex(random_bytes(8)) . '.png'; file_put_contents($temp_png, $image_data); // Create output JPG filename $generated_image = 'generated_' . time() . '_' . bin2hex(random_bytes(8)) . '.jpg'; // Build ImageMagick convert command with optimization $quality = 85; // Balanced quality setting $cmd = "convert \"$temp_png\" -strip -interlace Plane -gaussian-blur 0.05 -quality $quality "; $cmd .= "-sampling-factor 4:2:0 \"$generated_image\" 2>&1"; // Execute conversion $output = []; $returnVar = 0; exec($cmd, $output, $returnVar); if ($returnVar === 0 && file_exists($generated_image)) { // Get file sizes for comparison $originalSize = filesize($temp_png); $convertedSize = filesize($generated_image); // Clean up temporary PNG file if (file_exists($temp_png)) { unlink($temp_png); } // Clean up old generated files foreach (glob("generated_*.png") as $file) { if ($file != $generated_image && (time() - filemtime($file)) > 3600) { unlink($file); } } // Store size information for display $size_info = array( 'original' => round($originalSize / 1024, 2), 'converted' => round($convertedSize / 1024, 2), 'reduction' => round((($originalSize - $convertedSize) / $originalSize) * 100, 2) ); } else { // If conversion fails, keep the original PNG if (file_exists($temp_png)) { $generated_image = $temp_png; } $error_message = "Image conversion failed. Using original PNG format."; } } } curl_close($ch); } } } else if ($_SERVER["REQUEST_METHOD"] == "GET" && isset($_GET['load_prompt'])) { // Load saved prompt into textarea $saved_prompts = loadSavedPrompts(); $prompt = isset($saved_prompts[$_GET['load_prompt']]) ? $saved_prompts[$_GET['load_prompt']] : ''; } ?> Stable Diffusion Image Generator

Stable Diffusion Image Generator



How to use LORAs:

Include LORAs using: [lora-name:weight]
Example: a beautiful landscape by [my-artist-lora:0.8]
Weight values: 0.1 to 1.0
Note: Do not use angle brackets (< >). Use square brackets instead.


Saved Prompts
">

">
Enter your prompt:
Width:
Height:
Steps:
CFG Scale:
Sampler:

"> Save Current Prompt
Prompt Name:

Generated Image:

Generated image
Download Generated Image

Original size: KB
Converted size: KB
Size reduction: %

Parameters used:
Prompt:
Processed Prompt:
Size: x
Steps:
CFG Scale:
Sampler:


Error: