Spaces:
Running
Running
Download index.html from BlueNinjask/mockup-generator: direct link, hf CLI and curl.
- Browser
- Download file 48.7 kB
-
https://huggingface.co/spaces/BlueNinjask/mockup-generator/resolve/main/index.html
- Command line
-
hf download hf://spaces/BlueNinjask/mockup-generator/index.html
-
curl -L -o index.html https://huggingface.co/spaces/BlueNinjask/mockup-generator/resolve/main/index.html
48.7 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Advanced Aesthetic Mockup Generator</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <script src="https://cdn.jsdelivr.net/npm/colorthief@2.3.2/dist/color-thief.umd.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script> | |
| <style> | |
| .dropzone { | |
| border: 2px dashed #cbd5e0; | |
| transition: all 0.3s ease; | |
| } | |
| .dropzone.active { | |
| border-color: #4299e1; | |
| background-color: #ebf8ff; | |
| } | |
| .mockup-container { | |
| min-height: 500px; | |
| background: linear-gradient(135deg, #f8fafc, #e2e8f0); | |
| } | |
| .color-palette { | |
| display: flex; | |
| height: 40px; | |
| border-radius: 8px; | |
| overflow: hidden; | |
| } | |
| .color-swatch { | |
| flex: 1; | |
| cursor: pointer; | |
| transition: transform 0.2s; | |
| } | |
| .color-swatch:hover { | |
| transform: scale(1.1); | |
| z-index: 2; | |
| } | |
| .bg-pattern { | |
| background-size: 40px 40px; | |
| background-repeat: repeat; | |
| } | |
| .bg-blur { | |
| backdrop-filter: blur(10px); | |
| } | |
| .bg-noise { | |
| background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.1'/%3E%3C/svg%3E"); | |
| } | |
| .bg-grain { | |
| background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.5' numOctaves='5' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.2'/%3E%3C/svg%3E"); | |
| } | |
| .bg-mesh { | |
| background-image: radial-gradient(circle at center, transparent 0%, rgba(255,255,255,0.1) 100%); | |
| } | |
| .bg-liquid { | |
| background: linear-gradient(45deg, transparent 65%, rgba(255,255,255,0.3) 65%) 0 0, | |
| linear-gradient(-45deg, transparent 65%, rgba(255,255,255,0.3) 65%) 0 0; | |
| background-size: 30px 30px; | |
| } | |
| .perspective-3d { | |
| transform-style: preserve-3d; | |
| perspective: 1000px; | |
| } | |
| .rotate-3d { | |
| transform: rotateX(-10deg) rotateY(15deg) rotateZ(0deg); | |
| } | |
| .shadow-3d { | |
| box-shadow: 20px 20px 50px rgba(0, 0, 0, 0.3); | |
| } | |
| .glass-effect { | |
| backdrop-filter: blur(16px) saturate(180%); | |
| background-color: rgba(255, 255, 255, 0.2); | |
| border: 1px solid rgba(255, 255, 255, 0.125); | |
| } | |
| .gradient-text { | |
| background-clip: text; | |
| -webkit-background-clip: text; | |
| color: transparent; | |
| } | |
| .slider-thumb::-webkit-slider-thumb { | |
| -webkit-appearance: none; | |
| appearance: none; | |
| width: 20px; | |
| height: 20px; | |
| border-radius: 50%; | |
| background: #4f46e5; | |
| cursor: pointer; | |
| } | |
| .slider-thumb::-moz-range-thumb { | |
| width: 20px; | |
| height: 20px; | |
| border-radius: 50%; | |
| background: #4f46e5; | |
| cursor: pointer; | |
| } | |
| .bg-checker { | |
| background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%239C92AC' fill-opacity='0.1' fill-rule='evenodd'%3E%3Cpath d='M0 0h10v10H0V0zm10 10h10v10H10V10z'/%3E%3C/g%3E%3C/svg%3E"); | |
| } | |
| @keyframes float { | |
| 0% { transform: translateY(0px); } | |
| 50% { transform: translateY(-20px); } | |
| 100% { transform: translateY(0px); } | |
| } | |
| .floating { | |
| animation: float 6s ease-in-out infinite; | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-50 font-sans"> | |
| <div class="container mx-auto px-4 py-8 max-w-7xl"> | |
| <div class="text-center mb-12"> | |
| <h1 class="text-5xl font-bold text-gray-900 mb-3 gradient-text bg-gradient-to-r from-blue-600 to-purple-600">Advanced Mockup Generator</h1> | |
| <p class="text-xl text-gray-600 max-w-3xl mx-auto">Create stunning product presentations with professional backgrounds and effects</p> | |
| </div> | |
| <div class="grid grid-cols-1 lg:grid-cols-4 gap-8"> | |
| <!-- Control Panel --> | |
| <div class="lg:col-span-1 bg-white rounded-2xl shadow-xl p-6 glass-effect"> | |
| <h2 class="text-2xl font-semibold mb-4 text-gray-800">Design Controls</h2> | |
| <!-- Image Upload --> | |
| <div class="mb-6"> | |
| <label class="block text-sm font-medium text-gray-700 mb-2">Upload Product Image</label> | |
| <div id="dropzone" class="dropzone rounded-xl p-8 text-center cursor-pointer bg-white/50 hover:bg-white/70 transition"> | |
| <div class="flex flex-col items-center justify-center"> | |
| <i class="fas fa-cloud-upload-alt text-4xl text-gray-400 mb-2"></i> | |
| <p class="text-gray-600">Drag & drop image here</p> | |
| <p class="text-xs text-gray-400 mt-1">(PNG, JPG, max 10MB)</p> | |
| </div> | |
| <input type="file" id="file-input" class="hidden" accept="image/*"> | |
| </div> | |
| <div id="file-preview" class="mt-3 flex justify-center hidden"> | |
| <img id="uploaded-image" class="max-h-40 rounded-lg shadow-sm"> | |
| </div> | |
| </div> | |
| <!-- Extracted Color Palette --> | |
| <div class="mb-6 hidden" id="color-palette-section"> | |
| <label class="block text-sm font-medium text-gray-700 mb-2">Extracted Color Palette</label> | |
| <div id="color-palette" class="color-palette mb-2 shadow-sm"></div> | |
| <p class="text-xs text-gray-500">Click to set as background</p> | |
| <div class="mt-3 grid grid-cols-2 gap-2"> | |
| <button id="auto-color-btn" class="bg-gray-100 hover:bg-gray-200 text-gray-800 py-1 px-3 rounded text-sm flex items-center justify-center"> | |
| <i class="fas fa-palette mr-1"></i> Auto Color | |
| </button> | |
| <button id="custom-color-btn" class="bg-gray-100 hover:bg-gray-200 text-gray-800 py-1 px-3 rounded text-sm flex items-center justify-center"> | |
| <i class="fas fa-eye-dropper mr-1"></i> Custom | |
| <input type="color" id="custom-color" class="ml-2 w-6 h-6 opacity-0 absolute"> | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Background Options --> | |
| <div class="mb-6"> | |
| <label class="block text-sm font-medium text-gray-700 mb-2">Background Style</label> | |
| <div class="grid grid-cols-3 gap-2"> | |
| <button data-bg="solid" class="bg-option bg-white/70 hover:bg-white p-2 rounded-xl flex flex-col items-center border border-gray-200"> | |
| <div class="w-8 h-8 bg-gradient-to-br from-gray-300 to-gray-400 mb-1 rounded-lg"></div> | |
| <span class="text-xs">Solid</span> | |
| </button> | |
| <button data-bg="gradient" class="bg-option bg-white/70 hover:bg-white p-2 rounded-xl flex flex-col items-center border border-gray-200"> | |
| <div class="w-8 h-8 bg-gradient-to-br from-blue-400 to-purple-500 mb-1 rounded-lg"></div> | |
| <span class="text-xs">Gradient</span> | |
| </button> | |
| <button data-bg="pattern" class="bg-option bg-white/70 hover:bg-white p-2 rounded-xl flex flex-col items-center border border-gray-200"> | |
| <div class="w-8 h-8 bg-gray-100 bg-pattern mb-1 rounded-lg" style="background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMCIgaGVpZ2h0PSIxMCI+CiAgPHBhdGggZD0iTS0xLDEgbDIsLTIgTS0xLDYgbDIsLTIgTTQsMSBsMiwtMiBNNCw2IGwyLC0yIE05LDEgbDIsLTIiIGZpbGw9Im5vbmUiIHN0cm9rZT0icmdiYSgwLDAsMCwuMDgpIiBzdHJva2Utd2lkdGg9IjEiLz4KPC9zdmc+')"></div> | |
| <span class="text-xs">Pattern</span> | |
| </button> | |
| <button data-bg="blur" class="bg-option bg-white/70 hover:bg-white p-2 rounded-xl flex flex-col items-center border border-gray-200"> | |
| <div class="w-8 h-8 bg-gray-300 bg-blur mb-1 rounded-lg"></div> | |
| <span class="text-xs">Blur</span> | |
| </button> | |
| <button data-bg="noise" class="bg-option bg-white/70 hover:bg-white p-2 rounded-xl flex flex-col items-center border border-gray-200"> | |
| <div class="w-8 h-8 bg-gray-200 bg-noise mb-1 rounded-lg"></div> | |
| <span class="text-xs">Noise</span> | |
| </button> | |
| <button data-bg="grain" class="bg-option bg-white/70 hover:bg-white p-2 rounded-xl flex flex-col items-center border border-gray-200"> | |
| <div class="w-8 h-8 bg-gray-200 bg-grain mb-1 rounded-lg"></div> | |
| <span class="text-xs">Grain</span> | |
| </button> | |
| <button data-bg="mesh" class="bg-option bg-white/70 hover:bg-white p-2 rounded-xl flex flex-col items-center border border-gray-200"> | |
| <div class="w-8 h-8 bg-gray-200 bg-mesh mb-1 rounded-lg"></div> | |
| <span class="text-xs">Mesh</span> | |
| </button> | |
| <button data-bg="liquid" class="bg-option bg-white/70 hover:bg-white p-2 rounded-xl flex flex-col items-center border border-gray-200"> | |
| <div class="w-8 h-8 bg-gray-200 bg-liquid mb-1 rounded-lg"></div> | |
| <span class="text-xs">Liquid</span> | |
| </button> | |
| <button data-bg="transparent" class="bg-option bg-white/70 hover:bg-white p-2 rounded-xl flex flex-col items-center border border-gray-200"> | |
| <div class="w-8 h-8 border border-gray-300 bg-checker mb-1 rounded-lg"></div> | |
| <span class="text-xs">Transparent</span> | |
| </button> | |
| </div> | |
| <!-- Gradient Direction --> | |
| <div id="gradient-controls" class="mt-3 hidden"> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Gradient Direction</label> | |
| <select id="gradient-direction" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-blue-500 focus:border-blue-500"> | |
| <option value="to right">Horizontal</option> | |
| <option value="to bottom">Vertical</option> | |
| <option value="to bottom right">Diagonal</option> | |
| <option value="135deg">Angle (135°)</option> | |
| <option value="to top right">Reverse Diagonal</option> | |
| <option value="radial">Radial</option> | |
| </select> | |
| </div> | |
| <!-- Pattern Options --> | |
| <div id="pattern-controls" class="mt-3 hidden"> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Pattern Style</label> | |
| <select id="pattern-style" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-blue-500 focus:border-blue-500"> | |
| <option value="dots">Dots</option> | |
| <option value="lines">Lines</option> | |
| <option value="grid">Grid</option> | |
| <option value="waves">Waves</option> | |
| <option value="zigzag">Zigzag</option> | |
| </select> | |
| </div> | |
| </div> | |
| <!-- Layout Options --> | |
| <div class="mb-6"> | |
| <label class="block text-sm font-medium text-gray-700 mb-2">Layout Style</label> | |
| <div class="grid grid-cols-3 gap-2"> | |
| <button data-layout="centered" class="layout-option bg-white/70 hover:bg-white p-2 rounded-xl flex flex-col items-center border border-gray-200"> | |
| <div class="w-8 h-8 border border-gray-300 mb-1 flex items-center justify-center rounded-lg"> | |
| <div class="w-6 h-6 bg-blue-400 rounded-lg"></div> | |
| </div> | |
| <span class="text-xs">Centered</span> | |
| </button> | |
| <button data-layout="floating" class="layout-option bg-white/70 hover:bg-white p-2 rounded-xl flex flex-col items-center border border-gray-200"> | |
| <div class="w-8 h-8 border border-gray-300 mb-1 flex items-center justify-center rounded-lg"> | |
| <div class="w-6 h-6 bg-blue-400 rounded-lg transform rotate-12"></div> | |
| </div> | |
| <span class="text-xs">Floating</span> | |
| </button> | |
| <button data-layout="perspective" class="layout-option bg-white/70 hover:bg-white p-2 rounded-xl flex flex-col items-center border border-gray-200"> | |
| <div class="w-8 h-8 border border-gray-300 mb-1 flex items-center justify-center rounded-lg"> | |
| <div class="w-6 h-6 bg-blue-400 rounded-lg transform perspective-3d rotate-3d"></div> | |
| </div> | |
| <span class="text-xs">3D View</span> | |
| </button> | |
| <button data-layout="shadow" class="layout-option bg-white/70 hover:bg-white p-2 rounded-xl flex flex-col items-center border border-gray-200"> | |
| <div class="w-8 h-8 border border-gray-300 mb-1 flex items-center justify-center rounded-lg"> | |
| <div class="w-6 h-6 bg-blue-400 rounded-lg shadow-xl"></div> | |
| </div> | |
| <span class="text-xs">Shadow</span> | |
| </button> | |
| <button data-layout="border" class="layout-option bg-white/70 hover:bg-white p-2 rounded-xl flex flex-col items-center border border-gray-200"> | |
| <div class="w-8 h-8 border border-gray-300 mb-1 flex items-center justify-center rounded-lg"> | |
| <div class="w-6 h-6 bg-blue-400 rounded-lg border-4 border-white"></div> | |
| </div> | |
| <span class="text-xs">Border</span> | |
| </button> | |
| <button data-layout="natural" class="layout-option bg-white/70 hover:bg-white p-2 rounded-xl flex flex-col items-center border border-gray-200"> | |
| <div class="w-8 h-8 border border-gray-300 mb-1 flex items-center justify-center rounded-lg"> | |
| <div class="w-6 h-6 bg-blue-400 rounded-full"></div> | |
| </div> | |
| <span class="text-xs">Natural</span> | |
| </button> | |
| </div> | |
| <!-- 3D Controls --> | |
| <div id="3d-controls" class="mt-3 hidden"> | |
| <div class="mb-2"> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">X Rotation</label> | |
| <input type="range" id="rotate-x" min="-45" max="45" value="-10" class="w-full slider-thumb"> | |
| </div> | |
| <div class="mb-2"> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Y Rotation</label> | |
| <input type="range" id="rotate-y" min="-45" max="45" value="15" class="w-full slider-thumb"> | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Z Rotation</label> | |
| <input type="range" id="rotate-z" min="-45" max="45" value="0" class="w-full slider-thumb"> | |
| </div> | |
| </div> | |
| <!-- Shadow Controls --> | |
| <div id="shadow-controls" class="mt-3 hidden"> | |
| <div class="mb-2"> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Shadow Size</label> | |
| <input type="range" id="shadow-size" min="0" max="50" value="25" class="w-full slider-thumb"> | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Shadow Opacity</label> | |
| <input type="range" id="shadow-opacity" min="0" max="100" value="30" class="w-full slider-thumb"> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Product Adjustments --> | |
| <div class="mb-6"> | |
| <label class="block text-sm font-medium text-gray-700 mb-2">Product Adjustments</label> | |
| <div class="mb-2"> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Size</label> | |
| <input type="range" id="product-size" min="30" max="100" value="70" class="w-full slider-thumb"> | |
| </div> | |
| <div class="mb-2"> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Brightness</label> | |
| <input type="range" id="product-brightness" min="80" max="120" value="100" class="w-full slider-thumb"> | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Contrast</label> | |
| <input type="range" id="product-contrast" min="80" max="120" value="100" class="w-full slider-thumb"> | |
| </div> | |
| </div> | |
| <!-- Text Options --> | |
| <div class="mb-6"> | |
| <label for="mockup-text" class="block text-sm font-medium text-gray-700 mb-1">Text Overlay</label> | |
| <input type="text" id="mockup-text" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-blue-500 focus:border-blue-500" placeholder="Add text to your mockup"> | |
| <div class="mt-2 grid grid-cols-2 gap-2"> | |
| <select id="text-color" class="px-3 py-2 border border-gray-300 rounded-lg focus:ring-blue-500 focus:border-blue-500"> | |
| <option value="text-white">White</option> | |
| <option value="text-black">Black</option> | |
| <option value="text-gray-700">Gray</option> | |
| <option value="text-primary">Primary</option> | |
| <option value="gradient-text bg-gradient-to-r from-blue-500 to-purple-600">Gradient</option> | |
| </select> | |
| <select id="text-position" class="px-3 py-2 border border-gray-300 rounded-lg focus:ring-blue-500 focus:border-blue-500"> | |
| <option value="top-left">Top Left</option> | |
| <option value="top-center">Top Center</option> | |
| <option value="top-right">Top Right</option> | |
| <option value="bottom-left">Bottom Left</option> | |
| <option value="bottom-center">Bottom Center</option> | |
| <option value="bottom-right">Bottom Right</option> | |
| </select> | |
| </div> | |
| <div class="mt-2"> | |
| <select id="text-font" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-blue-500 focus:border-blue-500"> | |
| <option value="font-sans">Sans-serif</option> | |
| <option value="font-serif">Serif</option> | |
| <option value="font-mono">Monospace</option> | |
| </select> | |
| </div> | |
| <div class="mt-2 grid grid-cols-3 gap-2"> | |
| <button id="text-bold" class="bg-gray-100 hover:bg-gray-200 text-gray-800 py-1 px-3 rounded-lg text-sm"> | |
| <i class="fas fa-bold"></i> | |
| </button> | |
| <button id="text-italic" class="bg-gray-100 hover:bg-gray-200 text-gray-800 py-1 px-3 rounded-lg text-sm"> | |
| <i class="fas fa-italic"></i> | |
| </button> | |
| <button id="text-underline" class="bg-gray-100 hover:bg-gray-200 text-gray-800 py-1 px-3 rounded-lg text-sm"> | |
| <i class="fas fa-underline"></i> | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Generate & Download --> | |
| <div class="grid grid-cols-2 gap-3"> | |
| <button id="generate-btn" class="bg-gradient-to-r from-blue-600 to-blue-500 hover:from-blue-700 hover:to-blue-600 text-white font-bold py-3 px-4 rounded-xl transition duration-200 flex items-center justify-center"> | |
| <i class="fas fa-sync-alt mr-2"></i> Update | |
| </button> | |
| <button id="randomize-btn" class="bg-gradient-to-r from-purple-600 to-purple-500 hover:from-purple-700 hover:to-purple-600 text-white font-bold py-3 px-4 rounded-xl transition duration-200 flex items-center justify-center"> | |
| <i class="fas fa-random mr-2"></i> Random | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Preview Section --> | |
| <div class="lg:col-span-3"> | |
| <div class="bg-white rounded-2xl shadow-xl overflow-hidden h-full"> | |
| <div class="p-4 border-b border-gray-200 flex justify-between items-center bg-white/80 backdrop-blur-sm"> | |
| <h2 class="text-xl font-semibold text-gray-800">Mockup Preview</h2> | |
| <div id="download-options" class="flex space-x-2 hidden"> | |
| <button id="download-png" class="bg-gradient-to-r from-green-600 to-green-500 hover:from-green-700 hover:to-green-600 text-white py-2 px-4 rounded-lg text-sm flex items-center"> | |
| <i class="fas fa-download mr-2"></i> PNG | |
| </button> | |
| <button id="download-jpg" class="bg-gradient-to-r from-blue-600 to-blue-500 hover:from-blue-700 hover:to-blue-600 text-white py-2 px-4 rounded-lg text-sm flex items-center"> | |
| <i class="fas fa-download mr-2"></i> JPG | |
| </button> | |
| <button id="copy-link" class="bg-gradient-to-r from-purple-600 to-purple-500 hover:from-purple-700 hover:to-purple-600 text-white py-2 px-4 rounded-lg text-sm flex items-center"> | |
| <i class="fas fa-link mr-2"></i> Copy Link | |
| </button> | |
| </div> | |
| </div> | |
| <div id="mockup-container" class="mockup-container p-8 flex items-center justify-center relative overflow-hidden"> | |
| <div id="empty-state" class="text-center text-gray-400"> | |
| <i class="fas fa-image text-6xl mb-4 opacity-30"></i> | |
| <p class="text-xl font-medium">Your mockup will appear here</p> | |
| <p class="text-sm mt-2 max-w-md mx-auto">Upload an image and customize your design with the controls on the left</p> | |
| <button id="sample-image-btn" class="mt-4 bg-gradient-to-r from-blue-500 to-purple-500 hover:from-blue-600 hover:to-purple-600 text-white font-medium py-2 px-6 rounded-lg transition duration-200 inline-flex items-center"> | |
| <i class="fas fa-magic mr-2"></i> Try Sample Image | |
| </button> | |
| </div> | |
| <div id="mockup-preview" class="w-full h-full hidden relative"> | |
| <!-- Generated mockup will appear here --> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| document.addEventListener('DOMContentLoaded', function() { | |
| const dropzone = document.getElementById('dropzone'); | |
| const fileInput = document.getElementById('file-input'); | |
| const filePreview = document.getElementById('file-preview'); | |
| const uploadedImage = document.getElementById('uploaded-image'); | |
| const colorPaletteSection = document.getElementById('color-palette-section'); | |
| const colorPalette = document.getElementById('color-palette'); | |
| const generateBtn = document.getElementById('generate-btn'); | |
| const randomizeBtn = document.getElementById('randomize-btn'); | |
| const mockupPreview = document.getElementById('mockup-preview'); | |
| const emptyState = document.getElementById('empty-state'); | |
| const downloadOptions = document.getElementById('download-options'); | |
| const mockupContainer = document.getElementById('mockup-container'); | |
| const colorThief = new ColorThief(); | |
| const sampleImageBtn = document.getElementById('sample-image-btn'); | |
| const autoColorBtn = document.getElementById('auto-color-btn'); | |
| const customColorBtn = document.getElementById('custom-color-btn'); | |
| const customColorInput = document.getElementById('custom-color'); | |
| // Background controls | |
| const gradientControls = document.getElementById('gradient-controls'); | |
| const patternControls = document.getElementById('pattern-controls'); | |
| // 3D controls | |
| const threeDControls = document.getElementById('3d-controls'); | |
| const rotateXInput = document.getElementById('rotate-x'); | |
| const rotateYInput = document.getElementById('rotate-y'); | |
| const rotateZInput = document.getElementById('rotate-z'); | |
| // Shadow controls | |
| const shadowControls = document.getElementById('shadow-controls'); | |
| const shadowSizeInput = document.getElementById('shadow-size'); | |
| const shadowOpacityInput = document.getElementById('shadow-opacity'); | |
| // Product adjustments | |
| const productSizeInput = document.getElementById('product-size'); | |
| const productBrightnessInput = document.getElementById('product-brightness'); | |
| const productContrastInput = document.getElementById('product-contrast'); | |
| // Text controls | |
| const textBoldBtn = document.getElementById('text-bold'); | |
| const textItalicBtn = document.getElementById('text-italic'); | |
| const textUnderlineBtn = document.getElementById('text-underline'); | |
| let currentImage = null; | |
| let dominantColor = '#4f46e5'; | |
| let colorPaletteArray = []; | |
| let bgStyle = 'gradient'; | |
| let layoutStyle = 'centered'; | |
| let textStyles = []; | |
| // Initialize with first options selected | |
| document.querySelector('.bg-option[data-bg="gradient"]').classList.add('ring-2', 'ring-blue-500'); | |
| document.querySelector('.layout-option[data-layout="centered"]').classList.add('ring-2', 'ring-blue-500'); | |
| // Handle drag and drop | |
| dropzone.addEventListener('click', () => fileInput.click()); | |
| dropzone.addEventListener('dragover', (e) => { | |
| e.preventDefault(); | |
| dropzone.classList.add('active'); | |
| }); | |
| dropzone.addEventListener('dragleave', () => { | |
| dropzone.classList.remove('active'); | |
| }); | |
| dropzone.addEventListener('drop', (e) => { | |
| e.preventDefault(); | |
| dropzone.classList.remove('active'); | |
| if (e.dataTransfer.files.length) { | |
| handleFile(e.dataTransfer.files[0]); | |
| } | |
| }); | |
| fileInput.addEventListener('change', () => { | |
| if (fileInput.files.length) { | |
| handleFile(fileInput.files[0]); | |
| } | |
| }); | |
| // Handle sample image | |
| sampleImageBtn.addEventListener('click', function() { | |
| currentImage = new Image(); | |
| currentImage.crossOrigin = 'Anonymous'; | |
| currentImage.src = 'https://images.unsplash.com/photo-1523275335684-37898b6baf30?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=500&q=80'; | |
| currentImage.onload = function() { | |
| // Display preview | |
| uploadedImage.src = currentImage.src; | |
| filePreview.classList.remove('hidden'); | |
| // Extract colors | |
| extractColors(currentImage); | |
| // Generate initial mockup | |
| generateMockup(); | |
| }; | |
| }); | |
| // Handle uploaded file | |
| function handleFile(file) { | |
| if (!file.type.match('image.*')) { | |
| alert('Please upload an image file (PNG or JPG)'); | |
| return; | |
| } | |
| if (file.size > 10 * 1024 * 1024) { | |
| alert('File too large (max 10MB)'); | |
| return; | |
| } | |
| const reader = new FileReader(); | |
| reader.onload = function(e) { | |
| currentImage = new Image(); | |
| currentImage.crossOrigin = 'Anonymous'; | |
| currentImage.src = e.target.result; | |
| currentImage.onload = function() { | |
| // Display preview | |
| uploadedImage.src = e.target.result; | |
| filePreview.classList.remove('hidden'); | |
| // Extract colors | |
| extractColors(currentImage); | |
| // Generate initial mockup | |
| generateMockup(); | |
| }; | |
| }; | |
| reader.readAsDataURL(file); | |
| } | |
| // Extract colors from image | |
| function extractColors(img) { | |
| try { | |
| // Get dominant color | |
| const dominant = colorThief.getColor(img); | |
| dominantColor = rgbToHex(dominant[0], dominant[1], dominant[2]); | |
| // Get color palette | |
| const palette = colorThief.getPalette(img, 6); | |
| colorPaletteArray = palette.map(color => rgbToHex(color[0], color[1], color[2])); | |
| // Display color palette | |
| displayColorPalette(colorPaletteArray); | |
| colorPaletteSection.classList.remove('hidden'); | |
| } catch (e) { | |
| console.error('Error extracting colors:', e); | |
| // Fallback colors | |
| dominantColor = '#4f46e5'; | |
| colorPaletteArray = ['#4f46e5', '#818cf8', '#c7d2fe', '#e0e7ff', '#f5f3ff', '#8b5cf6']; | |
| displayColorPalette(colorPaletteArray); | |
| colorPaletteSection.classList.remove('hidden'); | |
| } | |
| } | |
| // Convert RGB to HEX | |
| function rgbToHex(r, g, b) { | |
| return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); | |
| } | |
| // Display color palette | |
| function displayColorPalette(colors) { | |
| colorPalette.innerHTML = ''; | |
| colors.forEach((color, index) => { | |
| const swatch = document.createElement('div'); | |
| swatch.className = 'color-swatch'; | |
| swatch.style.backgroundColor = color; | |
| swatch.title = color; | |
| swatch.dataset.color = color; | |
| if (index === 0) { | |
| swatch.style.borderTopLeftRadius = '8px'; | |
| swatch.style.borderBottomLeftRadius = '8px'; | |
| } | |
| if (index === colors.length - 1) { | |
| swatch.style.borderTopRightRadius = '8px'; | |
| swatch.style.borderBottomRightRadius = '8px'; | |
| } | |
| swatch.addEventListener('click', () => { | |
| dominantColor = color; | |
| generateMockup(); | |
| }); | |
| colorPalette.appendChild(swatch); | |
| }); | |
| } | |
| // Auto color button | |
| autoColorBtn.addEventListener('click', function() { | |
| if (colorPaletteArray.length > 0) { | |
| // Pick a random color from the palette | |
| const randomColor = colorPaletteArray[Math.floor(Math.random() * colorPaletteArray.length)]; | |
| dominantColor = randomColor; | |
| generateMockup(); | |
| } | |
| }); | |
| // Custom color button | |
| customColorBtn.addEventListener('click', function() { | |
| customColorInput.click(); | |
| }); | |
| customColorInput.addEventListener('input', function() { | |
| dominantColor = this.value; | |
| generateMockup(); | |
| }); | |
| // Background style selection | |
| document.querySelectorAll('.bg-option').forEach(btn => { | |
| btn.addEventListener('click', function() { | |
| bgStyle = this.dataset.bg; | |
| document.querySelectorAll('.bg-option').forEach(b => b.classList.remove('ring-2', 'ring-blue-500')); | |
| this.classList.add('ring-2', 'ring-blue-500'); | |
| // Show/hide additional controls | |
| if (bgStyle === 'gradient') { | |
| gradientControls.classList.remove('hidden'); | |
| patternControls.classList.add('hidden'); | |
| } else if (bgStyle === 'pattern') { | |
| gradientControls.classList.add('hidden'); | |
| patternControls.classList.remove('hidden'); | |
| } else { | |
| gradientControls.classList.add('hidden'); | |
| patternControls.classList.add('hidden'); | |
| } | |
| generateMockup(); | |
| }); | |
| }); | |
| // Layout style selection | |
| document.querySelectorAll('.layout-option').forEach(btn => { | |
| btn.addEventListener('click', function() { | |
| layoutStyle = this.dataset.layout; | |
| document.querySelectorAll('.layout-option').forEach(b => b.classList.remove('ring-2', 'ring-blue-500')); | |
| this.classList.add('ring-2', 'ring-blue-500'); | |
| // Show/hide additional controls | |
| if (layoutStyle === 'perspective') { | |
| threeDControls.classList.remove('hidden'); | |
| shadowControls.classList.add('hidden'); | |
| } else if (layoutStyle === 'shadow') { | |
| threeDControls.classList.add('hidden'); | |
| shadowControls.classList.remove('hidden'); | |
| } else { | |
| threeDControls.classList.add('hidden'); | |
| shadowControls.classList.add('hidden'); | |
| } | |
| generateMockup(); | |
| }); | |
| }); | |
| // 3D controls | |
| [rotateXInput, rotateYInput, rotateZInput].forEach(input => { | |
| input.addEventListener('input', generateMockup); | |
| }); | |
| // Shadow controls | |
| [shadowSizeInput, shadowOpacityInput].forEach(input => { | |
| input.addEventListener('input', generateMockup); | |
| }); | |
| // Product adjustments | |
| [productSizeInput, productBrightnessInput, productContrastInput].forEach(input => { | |
| input.addEventListener('input', generateMockup); | |
| }); | |
| // Text styling | |
| [textBoldBtn, textItalicBtn, textUnderlineBtn].forEach(btn => { | |
| btn.addEventListener('click', function() { | |
| this.classList.toggle('bg-blue-500'); | |
| this.classList.toggle('text-white'); | |
| generateMockup(); | |
| }); | |
| }); | |
| // Randomize button | |
| randomizeBtn.addEventListener('click', function() { | |
| // Random background | |
| const bgOptions = document.querySelectorAll('.bg-option'); | |
| const randomBg = bgOptions[Math.floor(Math.random() * bgOptions.length)]; | |
| randomBg.click(); | |
| // Random layout | |
| const layoutOptions = document.querySelectorAll('.layout-option'); | |
| const randomLayout = layoutOptions[Math.floor(Math.random() * layoutOptions.length)]; | |
| randomLayout.click(); | |
| // Random 3D rotation if applicable | |
| if (layoutStyle === 'perspective') { | |
| rotateXInput.value = Math.floor(Math.random() * 90) - 45; | |
| rotateYInput.value = Math.floor(Math.random() * 90) - 45; | |
| rotateZInput.value = Math.floor(Math.random() * 90) - 45; | |
| } | |
| // Random shadow if applicable | |
| if (layoutStyle === 'shadow') { | |
| shadowSizeInput.value = Math.floor(Math.random() * 50); | |
| shadowOpacityInput.value = Math.floor(Math.random() * 100); | |
| } | |
| // Random product size | |
| productSizeInput.value = 30 + Math.floor(Math.random() * 70); | |
| productBrightnessInput.value = 80 + Math.floor(Math.random() * 40); | |
| productContrastInput.value = 80 + Math.floor(Math.random() * 40); | |
| // Random text color | |
| const textColors = document.getElementById('text-color').options; | |
| document.getElementById('text-color').selectedIndex = Math.floor(Math.random() * textColors.length); | |
| // Random text position | |
| const textPositions = document.getElementById('text-position').options; | |
| document.getElementById('text-position').selectedIndex = Math.floor(Math.random() * textPositions.length); | |
| // Random text style | |
| textBoldBtn.classList.toggle('bg-blue-500', Math.random() > 0.5); | |
| textBoldBtn.classList.toggle('text-white', Math.random() > 0.5); | |
| textItalicBtn.classList.toggle('bg-blue-500', Math.random() > 0.5); | |
| textItalicBtn.classList.toggle('text-white', Math.random() > 0.5); | |
| textUnderlineBtn.classList.toggle('bg-blue-500', Math.random() > 0.5); | |
| textUnderlineBtn.classList.toggle('text-white', Math.random() > 0.5); | |
| // Random text content | |
| const sampleTexts = ["Premium Quality", "New Collection", "Limited Edition", "Summer 2023", "Exclusive Design"]; | |
| document.getElementById('mockup-text').value = sampleTexts[Math.floor(Math.random() * sampleTexts.length)]; | |
| // Generate with random settings | |
| generateMockup(); | |
| }); | |
| // Generate mockup | |
| function generateMockup() { | |
| if (!currentImage) { | |
| alert('Please upload an image first'); | |
| return; | |
| } | |
| emptyState.classList.add('hidden'); | |
| mockupPreview.classList.remove('hidden'); | |
| downloadOptions.classList.remove('hidden'); | |
| // Clear previous mockup | |
| mockupPreview.innerHTML = ''; | |
| // Create mockup container | |
| const mockup = document.createElement('div'); | |
| mockup.className = 'w-full h-full flex items-center justify-center relative'; | |
| // Apply background style | |
| applyBackgroundStyle(mockup); | |
| // Create image container with layout style | |
| const imgContainer = document.createElement('div'); | |
| imgContainer.className = 'relative transition-all duration-300'; | |
| applyLayoutStyle(imgContainer); | |
| // Add the product image | |
| const productImg = document.createElement('img'); | |
| productImg.src = currentImage.src; | |
| productImg.className = 'max-w-full max-h-full object-contain transition-all duration-300'; | |
| productImg.style.width = `${productSizeInput.value}%`; | |
| productImg.style.filter = `brightness(${productBrightnessInput.value}%) contrast(${productContrastInput.value}%)`; | |
| imgContainer.appendChild(productImg); | |
| // Add text overlay if provided | |
| const mockupText = document.getElementById('mockup-text').value; | |
| const textColor = document.getElementById('text-color').value; | |
| const textPosition = document.getElementById('text-position').value; | |
| const textFont = document.getElementById('text-font').value; | |
| if (mockupText) { | |
| const textOverlay = document.createElement('div'); | |
| let textClasses = `absolute ${getTextPositionClass(textPosition)} p-4 ${textColor} ${textFont} text-2xl font-bold transition-all duration-300`; | |
| // Apply text styles | |
| if (textBoldBtn.classList.contains('bg-blue-500')) textClasses += ' font-bold'; | |
| if (textItalicBtn.classList.contains('bg-blue-500')) textClasses += ' italic'; | |
| if (textUnderlineBtn.classList.contains('bg-blue-500')) textClasses += ' underline'; | |
| textOverlay.className = textClasses; | |
| textOverlay.style.textShadow = '0 2px 4px rgba(0,0,0,0.3)'; | |
| textOverlay.textContent = mockupText; | |
| imgContainer.appendChild(textOverlay); | |
| } | |
| mockup.appendChild(imgContainer); | |
| mockupPreview.appendChild(mockup); | |
| } | |
| // Apply background style | |
| function applyBackgroundStyle(element) { | |
| // Reset background | |
| element.className = 'w-full h-full flex items-center justify-center relative'; | |
| const gradientDirection = document.getElementById('gradient-direction').value; | |
| const patternStyle = document.getElementById('pattern-style').value; | |
| switch(bgStyle) { | |
| case 'solid': | |
| element.style.backgroundColor = dominantColor; | |
| break; | |
| case 'gradient': | |
| if (gradientDirection === 'radial') { | |
| element.style.background = `radial-gradient(circle, ${dominantColor}, ${lightenColor(dominantColor, 30)})`; | |
| } else { | |
| element.style.background = `linear-gradient(${gradientDirection}, ${dominantColor}, ${lightenColor(dominantColor, 30)})`; | |
| } | |
| break; | |
| case 'pattern': | |
| element.style.backgroundColor = lightenColor(dominantColor, 40); | |
| element.classList.add('bg-pattern'); | |
| let patternSvg = ''; | |
| switch(patternStyle) { | |
| case 'dots': | |
| patternSvg = "data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23000000' fill-opacity='0.1' fill-rule='evenodd'%3E%3Ccircle cx='3' cy='3' r='3'/%3E%3Ccircle cx='13' cy='13' r='3'/%3E%3C/g%3E%3C/svg%3E"; | |
| break; | |
| case 'lines': | |
| patternSvg = "data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23000000' fill-opacity='0.1' fill-rule='evenodd'%3E%3Cpath d='M0 0h20v1H0zM0 5h20v1H0zM0 10h20v1H0zM0 15h20v1H0z'/%3E%3C/g%3E%3C/svg%3E"; | |
| break; | |
| case 'grid': | |
| patternSvg = "data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23000000' fill-opacity='0.1' fill-rule='evenodd'%3E%3Cpath d='M0 0h20v1H0zM0 5h20v1H0zM0 10h20v1H0zM0 15h20v1H0z'/%3E%3Cpath d='M0 0h1v20H0zM5 0h1v20H5zM10 0h1v20h-1zM15 0h1v20h-1z'/%3E%3C/g%3E%3C/svg%3E"; | |
| break; | |
| case 'waves': | |
| patternSvg = "data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 10c5.523 0 10-4.477 10-10S15.523 0 20 0v20C15.523 20 10 15.523 10 10S5.523 0 0 0v10z' fill='%23000000' fill-opacity='0.1'/%3E%3C/svg%3E"; | |
| break; | |
| case 'zigzag': | |
| patternSvg = "data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 10l5 5 5-5 5 5 5-5' stroke='%23000000' stroke-opacity='0.1' stroke-width='1' fill='none'/%3E%3C/svg%3E"; | |
| break; | |
| } | |
| element.style.backgroundImage = `url('${patternSvg}')`; | |
| break; | |
| case 'blur': | |
| element.style.backgroundColor | |
| </html> |