Skip to content

Instantly share code, notes, and snippets.

View DraconicDragon's full-sized avatar
💭
meow?

Drac DraconicDragon

💭
meow?
View GitHub Profile
@DraconicDragon
DraconicDragon / extract_webp_metadata.py
Last active May 20, 2025 17:59
Python script to read stealth (and normal usercomment) metadata from a given WebP (and probably PNG) image like how reForge does it. Ref.: https://github.com/Panchovix/stable-diffusion-webui-reForge/pull/361 and https://github.com/Panchovix/stable-diffusion-webui-reForge/blob/main/modules/stealth_infotext.py as well as the gist which i use to co…
import argparse
import gzip
import logging
from pathlib import Path
import piexif
from PIL import Image
# ─── Configuration ─────────────────────────────────────────────────────────────
EXTRACT_STEALTH_METADATA = False # Extract stealth metadata from embedded bits
@DraconicDragon
DraconicDragon / comfy_png2webp_multi_opt.py
Last active May 20, 2025 18:01
Python script to convert PNGs with ComfyUI workflow + A1111-style metadata to WebP while preserving the A1111-style data in the UserComment exif field and/or as stealth metadata in the WebP's alpha channel. Works for both lossy and lossless webp (for lossy webp the alpha channel is encoded losslessly). Ref.: https://github.com/Panchovix/stable-d…
# Before running the script, put it in the directory you want it to convert PNGs into WebPs
# Then run it, it will go through every image in the same directory the script is in (no single image mode sorry, too lazy)
# and save it in a subdirectory. It will skip any existing WebPs so if you want to replace the existing webps with new ones
# like with stealth enabled this time, if you had it disabled before, then youll have to delete the existing webps.
# There are some boolean values you can change as well as some other stuff in the "Configuration" part
# like a save as animated webp option which is useful for sharing the webp with a1111 style metadata in usercomment over discord
# because discord won't remove the metadata if it detects the webp as animated webp
# What this script doesn't do:
@DraconicDragon
DraconicDragon / clip_l_tokenize.py
Created April 17, 2025 01:10
script that downloads the json files and merge.txt from openai/clip-vit-large-patch14 using transformers required to tokenize text and then tokenizes given input and outputs the number of tokens as well as the tokens themselves
from transformers import CLIPTokenizer
# Load the tokenizer from the local directory
tokenizer = CLIPTokenizer.from_pretrained("openai/clip-vit-large-patch14")
# Your input text
text = input("Input text:\n")
# Tokenize the text
tokens = tokenizer(text, return_tensors="pt")
@DraconicDragon
DraconicDragon / change_DL_folder_perms.ps1
Created April 13, 2025 07:33
Im stupid so i had chatgpt make this script, i dont actually know if its doing anything but i hope so
# Define path
$downloadsPath = "$env:USERPROFILE\Downloads"
$user = "$env:USERNAME"
$identity = "$env:USERDOMAIN\$user"
# Get current ACL
$acl = Get-Acl $downloadsPath
# Remove all existing rules to start clean
$acl.Access | ForEach-Object { $acl.RemoveAccessRule($_) }
@DraconicDragon
DraconicDragon / run_florence2_simple.py
Last active May 11, 2025 16:55
Script for running Florence2 based models
import requests
import torch
from PIL import Image
from transformers import AutoModelForCausalLM, AutoProcessor
device = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
model_id = r"microsoft/Florence-2-base" # can also use path/to/huggingface/hub/florence2-repo-name/snapshots/hash or something like that
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch_dtype, trust_remote_code=True).to(device)
@DraconicDragon
DraconicDragon / launch.py
Created September 3, 2024 15:19
Stable Diffusion Webui (/Forge) custom colored console output. paste this somewhere at the top of launch.py
import sys
import re
class GreenOutput:
# regex pattern to match URLs, IP and ports
url_pattern = re.compile(
r'((http|https|ftp|ftps):\/\/' # protocol
r'(\d{1,3}\.){3}\d{1,3}' # ip
r'(?::\d+)?' # port number if existing
r'(?:[\/\w.,@?^=%&:/~+#-]*)?' # rest of URL
r'|' # OR
@DraconicDragon
DraconicDragon / png_with_exif2jpg.py
Last active May 12, 2025 13:55
This is better https://gist.github.com/DraconicDragon/a00740bcb6dc54070b48c69a141b1c62 | A PNG to JPG converter that preserves the EXIF metadata (mainly to convert AI generated images to save storage space)
import os
import tkinter as tk
from tkinter import filedialog
import piexif
import piexif.helper
from PIL import Image
class PNGtoJPGConverterApp:
@DraconicDragon
DraconicDragon / doodle.css
Created January 29, 2024 18:51
Discord Custom CSS with collapsable SideBars
:root {
--sidebar-w-collapsed: 36px; /*used for collapsable sidebar*/
--sidebar-h-extended: 240px;
--memberlist-collapsed: 62px;
--memberlist-expanded: 240px;
--memberlist-transition: 0.35s ease-in-out;
}
/*vc text is correct with channel sidebar and main chat margin*/
.chat_f8f70f { margin-left: 0px !important; }
@DraconicDragon
DraconicDragon / XAML_Chessboard.md
Last active October 8, 2023 14:08
XAML Chessboard with Gridview, ItemsPanel, ItemsTemplate

XAML Chessboard with Gridview, ItemsPanel, ItemsTemplate

XAML

<GridView
    Width="Auto"
    Height="Auto"
    ItemsSource="{x:Bind Chessboard}">
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <ItemsWrapGrid MaximumRowsOrColumns="8" Orientation="Horizontal" />
@DraconicDragon
DraconicDragon / PNG_SD_prompt_reader.dart
Created September 1, 2023 22:53
Dart script for reading EXIF metadata from AI generated images (prompt info, model, seed, etc.)
// https://dev.exiv2.org/projects/exiv2/wiki/The_Metadata_in_PNG_files
// tEXt chunk: text that can be represented in ISO/IEC 8859-1.
// use exif package instead for jpeg, etc
import 'dart:io';
import 'dart:typed_data';
import 'package:png_chunks_extract/png_chunks_extract.dart' as pngExtract; // i thank that this exists.
void main() {
File file = File('path/to/image.png');
final data = file.readAsBytesSync();