Anand commited on
Commit
d7d7f4e
·
2 Parent(s): 8074cb2 863c802

Merge pull request #130 from Gojo-Bots/eziobhadwa

Browse files
Powers/plugins/stickers.py CHANGED
@@ -255,13 +255,13 @@ async def memify_it(c: Gojo, m: Message):
255
  is_sticker = False
256
  if rep_to.sticker:
257
  is_sticker = True
258
- cheems,domge = await draw_meme(path,meme,is_sticker)
259
  await x.delete()
260
- xNx = await m.reply_photo(cheems,reply_markup=kb)
261
- await xNx.reply_sticker(domge,reply_markup=kb)
262
  try:
263
- os.remove(cheems)
264
- os.remove(domge)
265
  except Exception as e:
266
  LOGGER.error(e)
267
  LOGGER.error(format_exc())
 
255
  is_sticker = False
256
  if rep_to.sticker:
257
  is_sticker = True
258
+ output = await draw_meme(path,meme,is_sticker)
259
  await x.delete()
260
+ xNx = await m.reply_photo(output[0],reply_markup=kb)
261
+ await xNx.reply_sticker(output[1],reply_markup=kb)
262
  try:
263
+ os.remove(output[0])
264
+ os.remove(output[1])
265
  except Exception as e:
266
  LOGGER.error(e)
267
  LOGGER.error(format_exc())
Powers/utils/sticker_help.py CHANGED
@@ -135,113 +135,156 @@ async def get_document_from_file_id(
135
  file_reference=decoded.file_reference,
136
  )
137
 
138
- async def draw_meme(image_path, text:str,stick):
139
- """Hellbot se churaya hai hue hue hue..."""
140
- img = Image.open(image_path)
141
- i_width, i_height = img.size
142
- m_font = ImageFont.truetype(
143
- "./extras/comic.ttf", int((70 / 640) * i_width)
144
- )
145
- if ";" in text:
146
- upper_text, lower_text = text.split(";")
147
  else:
148
  upper_text = text
149
  lower_text = ""
150
- draw = ImageDraw.Draw(img)
151
- current_h, pad = 10, 5
152
- if upper_text:
153
- for u_text in textwrap.wrap(upper_text,width=15,subsequent_indent=" "):
154
- u_width, u_height = draw.textsize(u_text, font=m_font)
155
- draw.text(
156
- xy=(((i_width - u_width) / 2) - 1, int((current_h / 640) * i_width)),
157
- text=u_text,
158
- font=m_font,
159
- fill=(0, 0, 0),
160
- )
161
- draw.text(
162
- xy=(((i_width - u_width) / 2) + 1, int((current_h / 640) * i_width)),
163
- text=u_text,
164
- font=m_font,
165
- fill=(0, 0, 0),
166
- )
167
- draw.text(
168
- xy=((i_width - u_width) / 2, int(((current_h / 640) * i_width)) - 1),
169
- text=u_text,
170
- font=m_font,
171
- fill=(0, 0, 0),
172
- )
173
- draw.text(
174
- xy=(((i_width - u_width) / 2), int(((current_h / 640) * i_width)) + 1),
175
- text=u_text,
176
- font=m_font,
177
- fill=(0, 0, 0),
178
- )
179
- draw.text(
180
- xy=((i_width - u_width) / 2, int((current_h / 640) * i_width)),
181
- text=u_text,
182
- font=m_font,
183
- fill=(255, 255, 255),
184
- )
185
- current_h += u_height + pad
186
- if lower_text:
187
- for l_text in textwrap.wrap(upper_text,width=15,subsequent_indent=" "):
188
- u_width, u_height = draw.textsize(l_text, font=m_font)
189
- draw.text(
190
- xy=(
191
- ((i_width - u_width) / 2) - 1,
192
- i_height - u_height - int((20 / 640) * i_width),
193
- ),
194
- text=l_text,
195
- font=m_font,
196
- fill=(0, 0, 0),
197
- )
198
- draw.text(
199
- xy=(
200
- ((i_width - u_width) / 2) + 1,
201
- i_height - u_height - int((20 / 640) * i_width),
202
- ),
203
- text=l_text,
204
- font=m_font,
205
- fill=(0, 0, 0),
206
- )
207
- draw.text(
208
- xy=(
209
- (i_width - u_width) / 2,
210
- (i_height - u_height - int((20 / 640) * i_width)) - 1,
211
- ),
212
- text=l_text,
213
- font=m_font,
214
- fill=(0, 0, 0),
215
- )
216
- draw.text(
217
- xy=(
218
- (i_width - u_width) / 2,
219
- (i_height - u_height - int((20 / 640) * i_width)) + 1,
220
- ),
221
- text=l_text,
222
- font=m_font,
223
- fill=(0, 0, 0),
224
- )
225
- draw.text(
226
- xy=(
227
- (i_width - u_width) / 2,
228
- i_height - u_height - int((20 / 640) * i_width),
229
- ),
230
- text=l_text,
231
- font=m_font,
232
- fill=(255, 255, 255),
233
- )
234
- current_h += u_height + pad
235
 
236
- hue = image_path
237
- if stick:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  stick_path = image_path
239
  else:
240
- stick_path = await resize_file_to_sticker_size(hue)
241
- mee = tosticker(stick_path,"@memesofdank_memer_hu_vai.webp")
242
- img.save(hue)
243
- img.save(mee)
244
- return hue, mee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
 
246
  def toimage(image, filename=None, is_direc=False):
247
  filename = filename if filename else "gojo.jpg"
 
135
  file_reference=decoded.file_reference,
136
  )
137
 
138
+
139
+ async def draw_meme(image_path: str, text: str, sticker: bool) -> list:
140
+ _split = text.split(";", 1)
141
+ if len(_split) == 2:
142
+ lower_text = _split[1]
143
+ upper_text = _split[0]
 
 
 
144
  else:
145
  upper_text = text
146
  lower_text = ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
+ image = Image.open(image_path)
149
+ width, height = image.size
150
+
151
+ font_size = int(width / 15)
152
+ font = ImageFont.truetype("./extras/comic.ttf", font_size)
153
+
154
+ draw = ImageDraw.Draw(image)
155
+
156
+ upper_text_width, _ = draw.textsize(upper_text, font=font)
157
+ lower_text_width, lower_text_height = draw.textsize(lower_text, font=font)
158
+
159
+ upper_text_position = ((width - upper_text_width) // 2, height // 10)
160
+ lower_text_position = ((width - lower_text_width) // 2, height - lower_text_height - (height // 10))
161
+
162
+ draw.text(upper_text_position, upper_text, font=font, fill="white")
163
+ draw.text(lower_text_position, lower_text, font=font, fill="white")
164
+
165
+ if sticker:
166
  stick_path = image_path
167
  else:
168
+ stick_path = await resize_file_to_sticker_size(image_path)
169
+
170
+ image1 = image_path
171
+ image2 = tosticker(stick_path,"@memesofdank_memer_hu_vai.webp")
172
+
173
+ image.save(image1)
174
+ image.save(image2)
175
+
176
+ image.close()
177
+
178
+ return [image1, image2]
179
+
180
+
181
+ # async def draw_meme(image_path, text:str,stick):
182
+ # """Hellbot se churaya hai hue hue hue..."""
183
+ # img = Image.open(image_path)
184
+ # i_width, i_height = img.size
185
+ # m_font = ImageFont.truetype(
186
+ # "./extras/comic.ttf", int((70 / 640) * i_width)
187
+ # )
188
+ # if ";" in text:
189
+ # upper_text, lower_text = text.split(";")
190
+ # else:
191
+ # upper_text = text
192
+ # lower_text = ""
193
+ # draw = ImageDraw.Draw(img)
194
+ # current_h, pad = 10, 5
195
+ # if upper_text:
196
+ # for u_text in textwrap.wrap(upper_text,width=15,subsequent_indent=" "):
197
+ # u_width, u_height = draw.textsize(u_text, font=m_font)
198
+ # draw.text(
199
+ # xy=(((i_width - u_width) / 2) - 1, int((current_h / 640) * i_width)),
200
+ # text=u_text,
201
+ # font=m_font,
202
+ # fill=(0, 0, 0),
203
+ # )
204
+ # draw.text(
205
+ # xy=(((i_width - u_width) / 2) + 1, int((current_h / 640) * i_width)),
206
+ # text=u_text,
207
+ # font=m_font,
208
+ # fill=(0, 0, 0),
209
+ # )
210
+ # draw.text(
211
+ # xy=((i_width - u_width) / 2, int(((current_h / 640) * i_width)) - 1),
212
+ # text=u_text,
213
+ # font=m_font,
214
+ # fill=(0, 0, 0),
215
+ # )
216
+ # draw.text(
217
+ # xy=(((i_width - u_width) / 2), int(((current_h / 640) * i_width)) + 1),
218
+ # text=u_text,
219
+ # font=m_font,
220
+ # fill=(0, 0, 0),
221
+ # )
222
+ # draw.text(
223
+ # xy=((i_width - u_width) / 2, int((current_h / 640) * i_width)),
224
+ # text=u_text,
225
+ # font=m_font,
226
+ # fill=(255, 255, 255),
227
+ # )
228
+ # current_h += u_height + pad
229
+ # if lower_text:
230
+ # for l_text in textwrap.wrap(upper_text,width=15,subsequent_indent=" "):
231
+ # u_width, u_height = draw.textsize(l_text, font=m_font)
232
+ # draw.text(
233
+ # xy=(
234
+ # ((i_width - u_width) / 2) - 1,
235
+ # i_height - u_height - int((20 / 640) * i_width),
236
+ # ),
237
+ # text=l_text,
238
+ # font=m_font,
239
+ # fill=(0, 0, 0),
240
+ # )
241
+ # draw.text(
242
+ # xy=(
243
+ # ((i_width - u_width) / 2) + 1,
244
+ # i_height - u_height - int((20 / 640) * i_width),
245
+ # ),
246
+ # text=l_text,
247
+ # font=m_font,
248
+ # fill=(0, 0, 0),
249
+ # )
250
+ # draw.text(
251
+ # xy=(
252
+ # (i_width - u_width) / 2,
253
+ # (i_height - u_height - int((20 / 640) * i_width)) - 1,
254
+ # ),
255
+ # text=l_text,
256
+ # font=m_font,
257
+ # fill=(0, 0, 0),
258
+ # )
259
+ # draw.text(
260
+ # xy=(
261
+ # (i_width - u_width) / 2,
262
+ # (i_height - u_height - int((20 / 640) * i_width)) + 1,
263
+ # ),
264
+ # text=l_text,
265
+ # font=m_font,
266
+ # fill=(0, 0, 0),
267
+ # )
268
+ # draw.text(
269
+ # xy=(
270
+ # (i_width - u_width) / 2,
271
+ # i_height - u_height - int((20 / 640) * i_width),
272
+ # ),
273
+ # text=l_text,
274
+ # font=m_font,
275
+ # fill=(255, 255, 255),
276
+ # )
277
+ # current_h += u_height + pad
278
+
279
+ # hue = image_path
280
+ # if stick:
281
+ # stick_path = image_path
282
+ # else:
283
+ # stick_path = await resize_file_to_sticker_size(hue)
284
+ # mee = tosticker(stick_path,"@memesofdank_memer_hu_vai.webp")
285
+ # img.save(hue)
286
+ # img.save(mee)
287
+ # return hue, mee
288
 
289
  def toimage(image, filename=None, is_direc=False):
290
  filename = filename if filename else "gojo.jpg"