updated to silent print
This commit is contained in:
122
windows_print_service/chrome_extension/icons/generate_icons.py
Normal file
122
windows_print_service/chrome_extension/icons/generate_icons.py
Normal file
@@ -0,0 +1,122 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Generate PNG icons for Chrome extension
|
||||
Creates simple colored squares with printer icons
|
||||
"""
|
||||
|
||||
try:
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
PIL_AVAILABLE = True
|
||||
except ImportError:
|
||||
PIL_AVAILABLE = False
|
||||
|
||||
import os
|
||||
|
||||
def create_simple_icon(size, filename):
|
||||
"""Create a simple colored square icon"""
|
||||
if PIL_AVAILABLE:
|
||||
# Create image with PIL
|
||||
img = Image.new('RGBA', (size, size), (0, 123, 255, 255)) # Blue background
|
||||
draw = ImageDraw.Draw(img)
|
||||
|
||||
# Add a white border
|
||||
border_width = max(1, size // 16)
|
||||
draw.rectangle([0, 0, size-1, size-1], outline=(255, 255, 255, 255), width=border_width)
|
||||
|
||||
# Add text (P for Print)
|
||||
try:
|
||||
font_size = size // 2
|
||||
font = ImageFont.load_default()
|
||||
text = "P"
|
||||
bbox = draw.textbbox((0, 0), text, font=font)
|
||||
text_width = bbox[2] - bbox[0]
|
||||
text_height = bbox[3] - bbox[1]
|
||||
x = (size - text_width) // 2
|
||||
y = (size - text_height) // 2
|
||||
draw.text((x, y), text, fill=(255, 255, 255, 255), font=font)
|
||||
except:
|
||||
pass
|
||||
|
||||
img.save(filename, 'PNG')
|
||||
print(f"Created {filename} ({size}x{size})")
|
||||
else:
|
||||
# Create a minimal PNG file without PIL
|
||||
create_minimal_png(size, filename)
|
||||
|
||||
def create_minimal_png(size, filename):
|
||||
"""Create a minimal PNG file without PIL"""
|
||||
# This creates a very basic PNG file
|
||||
# Blue square with minimal PNG structure
|
||||
|
||||
import struct
|
||||
import zlib
|
||||
|
||||
# PNG signature
|
||||
png_signature = b'\x89PNG\r\n\x1a\n'
|
||||
|
||||
# IHDR chunk
|
||||
width = height = size
|
||||
bit_depth = 8
|
||||
color_type = 2 # RGB
|
||||
compression = 0
|
||||
filter_method = 0
|
||||
interlace = 0
|
||||
|
||||
ihdr_data = struct.pack('>IIBBBBB', width, height, bit_depth, color_type, compression, filter_method, interlace)
|
||||
ihdr_crc = zlib.crc32(b'IHDR' + ihdr_data) & 0xffffffff
|
||||
ihdr_chunk = struct.pack('>I', len(ihdr_data)) + b'IHDR' + ihdr_data + struct.pack('>I', ihdr_crc)
|
||||
|
||||
# IDAT chunk (blue pixels)
|
||||
pixels = []
|
||||
for y in range(height):
|
||||
row = [0] # Filter byte
|
||||
for x in range(width):
|
||||
# Blue color RGB(0, 123, 255)
|
||||
row.extend([0, 123, 255])
|
||||
pixels.extend(row)
|
||||
|
||||
pixel_data = bytes(pixels)
|
||||
compressed_data = zlib.compress(pixel_data)
|
||||
idat_crc = zlib.crc32(b'IDAT' + compressed_data) & 0xffffffff
|
||||
idat_chunk = struct.pack('>I', len(compressed_data)) + b'IDAT' + compressed_data + struct.pack('>I', idat_crc)
|
||||
|
||||
# IEND chunk
|
||||
iend_crc = zlib.crc32(b'IEND') & 0xffffffff
|
||||
iend_chunk = struct.pack('>I', 0) + b'IEND' + struct.pack('>I', iend_crc)
|
||||
|
||||
# Write PNG file
|
||||
with open(filename, 'wb') as f:
|
||||
f.write(png_signature)
|
||||
f.write(ihdr_chunk)
|
||||
f.write(idat_chunk)
|
||||
f.write(iend_chunk)
|
||||
|
||||
print(f"Created minimal {filename} ({size}x{size})")
|
||||
|
||||
def main():
|
||||
# Create icons directory if it doesn't exist
|
||||
icons_dir = "/home/ske087/quality_recticel/windows_print_service/chrome_extension/icons"
|
||||
|
||||
print("Creating Chrome extension icons...")
|
||||
print(f"PIL available: {PIL_AVAILABLE}")
|
||||
|
||||
# Create required icon sizes
|
||||
sizes = [16, 32, 48, 128]
|
||||
|
||||
for size in sizes:
|
||||
filename = os.path.join(icons_dir, f"icon{size}.png")
|
||||
create_simple_icon(size, filename)
|
||||
|
||||
print("✅ All icons created successfully!")
|
||||
print("\nIcons created:")
|
||||
for size in sizes:
|
||||
filename = f"icon{size}.png"
|
||||
filepath = os.path.join(icons_dir, filename)
|
||||
if os.path.exists(filepath):
|
||||
file_size = os.path.getsize(filepath)
|
||||
print(f" ✓ {filename} ({size}x{size}px, {file_size} bytes)")
|
||||
else:
|
||||
print(f" ✗ {filename} - FAILED")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user