ysn-rfd/text-dataset-tiny-code-script-py-format
USED of tahamajs/medicine_ds_persian for .parquet file USED of Alijafarixcs2/persian-it-llama2-2k for .parquet file USED of Abirate/english_quotes for .jsonl file NEW FILES (05/12/2025) NEW FILES (12/26/2025) NEW FILES (02/15/2026)
31.6k
1from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageEnhance
2import qrcode
3import hashlib
4import random
5import math
6import os
7import base64
8import datetime
9from cryptography.hazmat.primitives.asymmetric import rsa, padding
10from cryptography.hazmat.primitives import hashes, serialization
11from cryptography.hazmat.backends import default_backend
12
13# ======== Enhanced Configurations ========
14CERT_WIDTH, CERT_HEIGHT = 1200, 900
15MARGIN = 40
16BACKGROUND_COLOR = (248, 246, 240)
17BORDER_COLOR = (30, 30, 30)
18TITLE_COLOR = (15, 15, 15)
19TEXT_COLOR = (35, 35, 35)
20WATERMARK_COLOR = (40, 40, 40, 20)
21NOISE_INTENSITY = 4500
22PAPER_TEXTURE_OPACITY = 0.15
23HOLOGRAM_OPACITY = 0.35
24
25# ======== Certificate Information ========
26cert_info = {
27 "Name": "Yasin",
28 "Last Name": "Aryanfard",
29 "User ID": "YSNRFD",
30 "Membership Date": "April 1, 2023",
31 "Issued Date": datetime.datetime.now().strftime("%B %d, %Y"),
32 "Certificate ID": f"OPENAI-YSN-APR2023-CERT{random.randint(10000, 99999)}",
33 "Signed By": "ChatGPT-4o",
34 "Model ID": "GPT4O-REP-TRUST-2025",
35 "Issuer": "OpenAI, Inc."
36}
37
38# ======== RSA Key Generation ========
39def generate_rsa_keys():
40 private_key = rsa.generate_private_key(
41 public_exponent=65537,
42 key_size=4096,
43 backend=default_backend()
44 )
45 public_key = private_key.public_key()
46
47 # Save public key for verification
48 pem = public_key.public_bytes(
49 encoding=serialization.Encoding.PEM,
50 format=serialization.PublicFormat.SubjectPublicKeyInfo
51 )
52 with open('certificate_public_key.pem', 'wb') as f:
53 f.write(pem)
54
55 return private_key, public_key
56
57private_key, public_key = generate_rsa_keys()
58
59# ======== Enhanced Font Loading ========
60def load_font(name, size):
61 fallback_fonts = [
62 "arial.ttf", "arialbd.ttf", "times.ttf", "timesbd.ttf",
63 "cour.ttf", "courbd.ttf", "DejaVuSans.ttf", "DejaVuSans-Bold.ttf"
64 ]
65 try:
66 # اول سعی میکنیم فونت درخواستی را بارگذاری کنیم
67 return ImageFont.truetype(name, size)
68 except IOError:
69 # سپس فونتهای فالبک را امتحان میکنیم
70 for font_name in fallback_fonts:
71 try:
72 return ImageFont.truetype(font_name, size)
73 except IOError:
74 continue
75 # در نهایت از فونت پیشفرض سیستم استفاده میکنیم
76 return ImageFont.load_default()
77
78font_title = load_font("georgiaz.ttf", 42)
79font_header = load_font("georgiab.ttf", 24)
80font_text = load_font("georgia.ttf", 20)
81font_small = load_font("cour.ttf", 16)
82font_signature = load_font("BrushScriptStd.otf", 28)
83
84# ======== Digital Signature Generation ========
85data_string = "\n".join(f"{k}: {v}" for k, v in cert_info.items()).encode('utf-8')
86
87signature = private_key.sign(
88 data_string,
89 padding.PSS(
90 mgf=padding.MGF1(hashes.SHA512()),
91 salt_length=padding.PSS.MAX_LENGTH
92 ),
93 hashes.SHA512()
94)
95
96digital_signature = base64.b64encode(signature).decode('utf-8')
97verification_code = f"VER-{hashlib.sha3_256(data_string).hexdigest()[:10].upper()}"
98
99# ======== QR Code Generation ========
100def create_qr_code(data, size=220):
101 qr = qrcode.QRCode(
102 version=7,
103 error_correction=qrcode.constants.ERROR_CORRECT_H,
104 box_size=10,
105 border=4
106 )
107 qr.add_data(data)
108 qr.make(fit=True)
109
110 qr_img = qr.make_image(
111 fill_color="#002855",
112 back_color="#F8F6F0"
113 ).convert("RGBA")
114
115 # Add holographic effect
116 hologram = Image.new("RGBA", qr_img.size)
117 holo_draw = ImageDraw.Draw(hologram)
118 for i in range(0, qr_img.width, 5):
119 alpha = int(255 * (0.3 + 0.7 * abs(math.sin(i/50))))
120 holo_draw.line([(i, 0), (i, qr_img.height)],
121 fill=(100, 200, 255, alpha), width=3)
122
123 return Image.alpha_composite(qr_img, hologram)
124
125qr_img = create_qr_code(f"{digital_signature}|{verification_code}")
126
127# ======== Background Design ========
128def create_certificate_base():
129 # Base with gradient
130 base = Image.new("RGB", (CERT_WIDTH, CERT_HEIGHT), BACKGROUND_COLOR)
131 draw = ImageDraw.Draw(base)
132
133 # Draw subtle grid
134 for i in range(0, CERT_WIDTH, 40):
135 alpha = 15 if i % 120 == 0 else 8
136 draw.line([(i, 0), (i, CERT_HEIGHT)], fill=(200, 200, 200, alpha), width=1)
137 for i in range(0, CERT_HEIGHT, 40):
138 alpha = 15 if i % 120 == 0 else 8
139 draw.line([(0, i), (CERT_WIDTH, i)], fill=(200, 200, 200, alpha), width=1)
140
141 # Add paper texture
142 texture = Image.new("RGBA", (CERT_WIDTH, CERT_HEIGHT), (0, 0, 0, 0))
143 tex_draw = ImageDraw.Draw(texture)
144 for _ in range(15000):
145 x, y = random.randint(0, CERT_WIDTH), random.randint(0, CERT_HEIGHT)
146 alpha = random.randint(10, 25)
147 size = random.randint(1, 3)
148 tex_draw.ellipse([(x, y), (x+size, y+size)],
149 fill=(150, 150, 150, alpha))
150
151 return Image.alpha_composite(base.convert("RGBA"), texture).convert("RGB")
152
153# ======== Official Seal with OpenAI Logo ========
154def create_official_seal(diameter=200):
155 seal = Image.new("RGBA", (diameter, diameter), (0, 0, 0, 0))
156 draw = ImageDraw.Draw(seal)
157 center = diameter // 2
158
159 # Complex seal pattern
160 for i in range(1, 15):
161 alpha = int(255 * (1 - i/15))
162 radius = center - i*3
163 color = (0, 48, 92, alpha)
164 draw.ellipse(
165 [(center - radius, center - radius),
166 (center + radius, center + radius)],
167 outline=color,
168 width=2
169 )
170
171 # Ornate details
172 num_points = 24
173 for i in range(num_points):
174 angle = math.radians(i * 360/num_points)
175 x1 = center + int((diameter*0.42) * math.cos(angle))
176 y1 = center + int((diameter*0.42) * math.sin(angle))
177 x2 = center + int((diameter*0.47) * math.cos(angle))
178 y2 = center + int((diameter*0.47) * math.sin(angle))
179 draw.line([(x1, y1), (x2, y2)], fill=(0, 48, 92, 220), width=3)
180
181 # Add holographic effect
182 for i in range(0, diameter, 4):
183 alpha = int(180 * (0.4 + 0.6 * abs(math.sin(i/20))))
184 draw.arc(
185 [(i//4, i//4), (diameter-i//4, diameter-i//4)],
186 start=0,
187 end=360,
188 fill=(100, 200, 255, alpha),
189 width=2
190 )
191
192 # Seal text
193 text = "OFFICIAL SEAL • VERIFIED • DIGITAL"
194 font_seal = load_font("timesbd.ttf", 14)
195 for i, char in enumerate(text):
196 angle = math.radians(i * 360/len(text) - 90)
197 x = center + int(center*0.65 * math.cos(angle)) - 5
198 y = center + int(center*0.65 * math.sin(angle)) - 5
199 draw.text((x, y), char, font=font_seal, fill=(0, 48, 92, 255))
200
201 # Add OpenAI logo to center of seal
202 try:
203 logo = Image.open("openai_seal.png").convert("RGBA")
204 logo_size = diameter // 2 # Size relative to seal diameter
205 logo.thumbnail((logo_size, logo_size), Image.LANCZOS)
206 logo_pos = (center - logo.width // 2, center - logo.height // 2)
207
208 # Create glow effect around logo
209 glow = Image.new("RGBA", (logo.width+10, logo.height+10), (0,0,0,0))
210 glow_draw = ImageDraw.Draw(glow)
211 glow_draw.ellipse([(0,0), (logo.width+10, logo.height+10)],
212 fill=(100, 200, 255, 60))
213 glow = glow.filter(ImageFilter.GaussianBlur(radius=5))
214
215 # Paste glow then logo
216 seal.paste(glow, (logo_pos[0]-5, logo_pos[1]-5), glow)
217 seal.paste(logo, logo_pos, logo)
218 except Exception as e:
219 print(f"⚠️ Could not load openai_seal.png: {e}")
220 # Draw simple OpenAI-inspired logo as fallback
221 draw.regular_polygon((center, center, diameter//4),
222 n_sides=6,
223 fill=(0, 48, 92, 180))
224
225 return seal
226
227# ======== Main Certificate Creation ========
228certificate = create_certificate_base().convert("RGBA")
229draw = ImageDraw.Draw(certificate)
230
231# Border design
232for i, thickness in enumerate([8, 5, 3, 1]):
233 offset = MARGIN - i*3
234 draw.rectangle(
235 [offset, offset, CERT_WIDTH - offset, CERT_HEIGHT - offset],
236 outline=(30, 30, 30),
237 width=thickness
238 )
239
240# Title section
241title = "CERTIFICATE OF AUTHENTICITY"
242bbox = draw.textbbox((0, 0), title, font=font_title)
243draw.text(
244 ((CERT_WIDTH - bbox[2])/2, MARGIN + 30),
245 title,
246 fill=TITLE_COLOR,
247 font=font_title
248)
249
250subtitle = "Issued by OpenAI for Distinguished Contribution"
251font_subtitle = load_font("georgiai.ttf", 22)
252bbox = draw.textbbox((0, 0), subtitle, font=font_subtitle)
253draw.text(
254 ((CERT_WIDTH - bbox[2])/2, MARGIN + 90),
255 subtitle,
256 fill=(70, 70, 70),
257 font=font_subtitle
258)
259
260# Decorative elements
261draw.line(
262 [(MARGIN+50, MARGIN+150), (CERT_WIDTH-MARGIN-50, MARGIN+150)],
263 fill=(150, 150, 150),
264 width=2
265)
266
267# Certificate information
268info_y = MARGIN + 180
269for key, value in cert_info.items():
270 draw.text(
271 (MARGIN+80, info_y),
272 f"{key}:",
273 font=font_header,
274 fill=(80, 80, 80))
275 draw.text(
276 (MARGIN+300, info_y),
277 value,
278 font=font_text,
279 fill=TEXT_COLOR)
280 info_y += 50
281
282# Security section
283info_y += 30
284draw.text(
285 (MARGIN+80, info_y),
286 "Digital Verification:",
287 font=font_header,
288 fill=(80, 80, 80))
289draw.text(
290 (MARGIN+300, info_y),
291 verification_code,
292 font=font_text,
293 fill=(0, 70, 120))
294info_y += 40
295
296# Digital signature block
297sig_text = "Cryptographic Signature:"
298draw.text((MARGIN+80, info_y), sig_text, font=font_small, fill=(100, 100, 100))
299info_y += 25
300signature_lines = [digital_signature[i:i+64] for i in range(0, len(digital_signature), 64)]
301for line in signature_lines[:4]:
302 draw.text((MARGIN+100, info_y), line, font=font_small, fill=(70, 70, 70))
303 info_y += 22
304
305# Official elements with OpenAI logo
306seal = create_official_seal()
307certificate.paste(
308 seal,
309 (CERT_WIDTH - MARGIN - seal.width - 50, MARGIN + 180),
310 seal
311)
312
313qr_position = (CERT_WIDTH - MARGIN - qr_img.width, CERT_HEIGHT - MARGIN - qr_img.height - 50)
314certificate.paste(qr_img, qr_position, qr_img)
315
316# Signature area
317signature_y = CERT_HEIGHT - MARGIN - 150
318draw.line(
319 [(MARGIN+100, signature_y), (MARGIN+400, signature_y)],
320 fill=(30, 30, 30),
321 width=2
322)
323draw.text(
324 (MARGIN+100, signature_y + 10),
325 "Dr. Sam Altman, Chief Executive Officer",
326 font=font_small,
327 fill=(60, 60, 60))
328draw.text(
329 (MARGIN+100, signature_y - 40),
330 "Authorized Signature",
331 font=font_signature,
332 fill=(30, 30, 30))
333
334# Security watermarks
335watermarks = [
336 "SECURE DOCUMENT", "OFFICIAL RECORD", "DO NOT DUPLICATE",
337 "VERIFIED", cert_info['Certificate ID'], verification_code,
338 "PROTECTED CONTENT", "DIGITALLY SIGNED", "OPENAI AUTHENTICATED"
339]
340
341for _ in range(150):
342 wm_text = random.choice(watermarks)
343 txt_img = Image.new("RGBA", (400, 40), (0, 0, 0, 0))
344 txt_draw = ImageDraw.Draw(txt_img)
345
346 alpha = random.randint(15, 30)
347 txt_draw.text(
348 (10, 10),
349 wm_text,
350 font=font_small,
351 fill=(40, 40, 40, alpha))
352
353 angle = random.uniform(-45, 45)
354 txt_img = txt_img.rotate(angle, expand=True, resample=Image.BICUBIC)
355
356 x = random.randint(0, CERT_WIDTH - txt_img.width)
357 y = random.randint(0, CERT_HEIGHT - txt_img.height)
358 certificate.paste(txt_img, (x, y), txt_img)
359
360# Final touches
361certificate = certificate.filter(ImageFilter.SMOOTH)
362certificate = certificate.filter(ImageFilter.SHARPEN)
363
364# Save certificate
365output_filename = f"OpenAI_Certificate_{cert_info['Certificate ID']}.png"
366certificate.save(output_filename, dpi=(300, 300), quality=100)
367print(f"✅ Professional certificate created: {output_filename}")
368print(f"🔑 Public key saved to: certificate_public_key.pem")