# Code Custodian File ID: 2C83D16D-B833-4568-AF2C-2AA7D438A3B1 import os import sys import math from AppKit import ( NSImage, NSBitmapImageRep, NSBezierPath, NSColor, NSFont, NSFontAttributeName, NSForegroundColorAttributeName, NSParagraphStyle, NSMutableParagraphStyle, NSCenterTextAlignment, NSCompositeSourceOver, NSCompositingOperationCopy, NSPNGFileType, NSRect, NSPoint, NSSize, NSGradient ) def create_circular_badge_native( character_path, output_path, badge_text="THE GROOVY PANDA", outer_border_color=(0.0, 0.2, 0.9, 1.0), # Royal Blue inner_grad_start=(0.4, 0.65, 1.0, 1.0), # Sky Blue Center inner_grad_end=(0.75, 0.25, 0.95, 1.0), # Vibrant Lavender Edge border_width=28.0, canvas_size=2048.0 ): print(f"🛠️ [Native AppKit] Compositing Pre-Press Badge for: {os.path.basename(character_path)}...") # 1. Create Base Bitmap Context size = NSSize(canvas_size, canvas_size) img = NSImage.alloc().initWithSize_(size) img.lockFocus() center_x = canvas_size / 2.0 center_y = canvas_size / 2.0 radius = (canvas_size / 2.0) - border_width - 15.0 # 2. Draw Soft Radial Gradient Background Circle circle_path = NSBezierPath.bezierPathWithOvalInRect_( NSRect(NSPoint(center_x - radius, center_y - radius), NSSize(radius * 2.0, radius * 2.0)) ) circle_path.addClip() # Radial Gradient (Sky Blue center -> Lavender/Purple edge) c_start = NSColor.colorWithCalibratedRed_green_blue_alpha_(*inner_grad_start) c_end = NSColor.colorWithCalibratedRed_green_blue_alpha_(*inner_grad_end) gradient = NSGradient.alloc().initWithStartingColor_endingColor_(c_start, c_end) gradient.drawFromCenter_radius_toCenter_radius_options_( NSPoint(center_x, center_y), 0.0, NSPoint(center_x, center_y), radius, 0 ) # 3. Composite 3D Character Anchor (Cutout / Alpha) if os.path.exists(character_path): char_img = NSImage.alloc().initWithContentsOfFile_(character_path) if char_img: # Scale character to fit upper 70% of the badge char_w = radius * 1.35 char_h = radius * 1.35 char_x = center_x - (char_w / 2.0) char_y = center_y - (char_h / 2.0) + (radius * 0.08) char_rect = NSRect(NSPoint(char_x, char_y), NSSize(char_w, char_h)) char_img.drawInRect_fromRect_operation_fraction_( char_rect, NSRect(NSPoint(0, 0), char_img.size()), NSCompositeSourceOver, 1.0 ) # 4. Draw Circular Border Ring (Reset clip) img.unlockFocus() img.lockFocus() border_color = NSColor.colorWithCalibratedRed_green_blue_alpha_(*outer_border_color) border_path = NSBezierPath.bezierPathWithOvalInRect_( NSRect(NSPoint(center_x - radius, center_y - radius), NSSize(radius * 2.0, radius * 2.0)) ) border_path.setLineWidth_(border_width) border_color.setStroke() border_path.stroke() # 5. Render Retro Typography ("THE GROOVY PANDA") font_size = radius * 0.22 font = NSFont.fontWithName_size_("Impact", font_size) or NSFont.boldSystemFontOfSize_(font_size) style = NSMutableParagraphStyle.alloc().init() style.setAlignment_(NSCenterTextAlignment) # Text Shadow shadow_attrs = { NSFontAttributeName: font, NSForegroundColorAttributeName: NSColor.colorWithCalibratedRed_green_blue_alpha_(0.0, 0.0, 0.0, 0.4), NSParagraphStyle: style } text_attrs = { NSFontAttributeName: font, NSForegroundColorAttributeName: border_color, NSParagraphStyle: style } text_w = radius * 1.7 text_h = font_size * 1.5 text_x = center_x - (text_w / 2.0) text_y = center_y - radius + (radius * 0.18) # Draw Shadow then Text text_str = str(badge_text) text_str.drawInRect_withAttributes_( NSRect(NSPoint(text_x + 3.0, text_y - 3.0), NSSize(text_w, text_h)), shadow_attrs ) text_str.drawInRect_withAttributes_( NSRect(NSPoint(text_x, text_y), NSSize(text_w, text_h)), text_attrs ) img.unlockFocus() # 6. Export 300 DPI Master PNG tiff_data = img.TIFFRepresentation() bitmap = NSBitmapImageRep.imageRepWithData_(tiff_data) png_data = bitmap.representationUsingType_properties_(NSPNGFileType, {}) os.makedirs(os.path.dirname(output_path), exist_ok=True) png_data.writeToFile_atomically_(output_path, True) size_kb = os.path.getsize(output_path) / 1024 print(f"🎉 [AppKit Pre-Press] 300 DPI Badge Saved: {output_path} ({size_kb:.1f} KB)") if __name__ == "__main__": base = "/Volumes/FACTORY_SSD/warezfactory/Art_Cannon" # Willow Badge willow_src = f"{base}/Characters/Willow/willow_dna_anchor.png" willow_dst = f"{base}/PrePress/DTF_Apparel/willow_official_badge_300dpi.png" if os.path.exists(willow_src): create_circular_badge_native(willow_src, willow_dst, badge_text="THE GROOVY PANDA") # Arlo Badge arlo_src = f"{base}/Characters/Arlo/arlo_dna_anchor.png" arlo_dst = f"{base}/PrePress/DTF_Apparel/arlo_official_badge_300dpi.png" if os.path.exists(arlo_src): create_circular_badge_native(arlo_src, arlo_dst, badge_text="THE GROOVY PANDA") # Copy to Stickers_UV os.system(f"cp '{willow_dst}' '{base}/PrePress/Stickers_UV/'") os.system(f"cp '{arlo_dst}' '{base}/PrePress/Stickers_UV/'") print("✅ Pre-Press Badges published to DTF_Apparel and Stickers_UV.")