image_pic_deal.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. """
  2. """
  3. import cv2
  4. import numpy as np
  5. from PIL import Image, ImageDraw, ImageFont
  6. from .data import DataModeAutoDealPics
  7. class OnePicDeal(object):
  8. def __init__(self,token):
  9. # 数据模型
  10. self.token = token
  11. self.data_mode_auto_deal_pics = DataModeAutoDealPics(token)
  12. def check_shoe_is_right(self, im=None, image_path=None):
  13. # 先进行API识别左右脚
  14. if im is None:
  15. im = Image.open(image_path)
  16. try:
  17. r_data = self.data_mode_auto_deal_pics.check_is_right_foot_by_api(image=im)
  18. except BaseException as e:
  19. r_data = None
  20. print("20", e)
  21. flag = self.check_shoe_is_right_by_pixel(im=im)
  22. if r_data:
  23. if "拖鞋" in r_data:
  24. flag = flag is not True
  25. if flag:
  26. print("自动识别----->这是左脚")
  27. else:
  28. print("自动识别----->这是右脚")
  29. return flag
  30. def check_shoe_is_right_by_pixel(self, im=None, image_path=None):
  31. if im is None:
  32. im = Image.open(image_path)
  33. # 注意,只支持透明图
  34. # 打开图像文件
  35. im = im.crop(im.getbbox())
  36. # image.show()
  37. # 获取图像第一行的像素数据
  38. pixel_data = im.load()
  39. pix_list = []
  40. h = int(im.height / 20)
  41. for i in range(im.width):
  42. _r, _g, _b, _a = pixel_data[i, h]
  43. if _a > 10:
  44. pix_list.append(i)
  45. left_f_num = 0
  46. middle_w = int(im.width / 2)
  47. for i in pix_list:
  48. if i < middle_w:
  49. left_f_num += 1
  50. else:
  51. left_f_num -= 1
  52. if left_f_num > 0:
  53. return True
  54. else:
  55. return False
  56. def how_to_use(self):
  57. # 单图缩放处理
  58. a = {"command": "resize",
  59. "plugins_mode": "relative", # pixel 相对(宽度、高度、其他参考图),或绝对像素
  60. "base_im": {"im": "im"}, # 参考基于其他图 PIL格式
  61. "base": "width", # base:pixel,width,height,by_im 基于长边、基于短边 (基于短边时,则缩放到指定尺寸)by_im确保能塞进参考图内
  62. "value": 649, # 固定值,如果为百分比,则为0
  63. "percentage": 0, } # 百分比
  64. # 单图圆角处理
  65. a = {"command": "radius", # radius
  66. "plugins_mode": "relative", # pixel 相对(短边),或绝对像素
  67. "circular_pos": (0, 1, 0, 1), # 从左上角顺时针,记录圆角数量
  68. "value": 649, # 固定值,如果为百分比,则为0
  69. "percentage": 0, } # 百分比
  70. # 单图处理成圆形
  71. a = {"command": "circular", # circular
  72. }
  73. # 单图旋转处理
  74. a = {"command": "rotate",
  75. "plugins_mode": "",
  76. "value": 649, # 固定值 顺时针
  77. }
  78. # 图片粘贴处理
  79. a = {
  80. "command": "paste_img",
  81. "img": {"im": "im"},
  82. "pos": {"plugins_mode": "relative", # pixel
  83. "base": "center", # nw,nc,ne,ec ... 各个方向参考点
  84. "value": (100, 100),
  85. "percentage": (0.5, 0.5),
  86. },
  87. "margins": (0, 0, 0, 0), # 上下左右边距
  88. }
  89. # 图片剪裁处理
  90. a = {
  91. "command": "crop_img",
  92. "img": {"im": "im"},
  93. "pos": {"plugins_mode": "relative", # pixel
  94. "base": "center", # nw,nc,ne,ec ... 各个方向参考点
  95. "value": (100, 100, 10, 10),
  96. },
  97. "color_fill": (255, 255, 255)
  98. }
  99. # 图片添加文字
  100. a = {
  101. "command": "add_text",
  102. "pos": {"plugins_mode": "relative", # pixel
  103. "base": "center", # nw,nc,ne,ec ... 各个方向参考点
  104. "value": (100, 100),
  105. "percentage": 0, },
  106. "font": "",
  107. "text": "",
  108. "anchor": "", # mm 为居中 ma 为左右居中,上面居顶
  109. "align": "对齐方式",
  110. "direction": "文本的方向",
  111. "max_len_one_line": "单行长度",
  112. "spacing": 10,
  113. "fill": "文字颜色",
  114. }
  115. def add_text(self, img: Image, command):
  116. draw_1 = ImageDraw.Draw(img)
  117. # 定义字体,你需要有一个.ttf字体文件
  118. font = command["font"]
  119. text = command["text"]
  120. spacing = 4 if not command["spacing"] else command["spacing"]
  121. fill = command["fill"]
  122. anchor = None if not command["anchor"] else command["anchor"]
  123. align = "left" if not command["align"] else command["align"] # left, center 或 right
  124. _, _, text_width, text_height = draw_1.textbbox((0, 0), text, font=font)
  125. xy = (0, 0)
  126. if command["pos"]["plugins_mode"] == "pixel":
  127. value = command["pos"]["value"]
  128. xy = value
  129. draw_1.multiline_text(xy, text,
  130. fill=fill,
  131. font=font,
  132. anchor=anchor,
  133. spacing=spacing,
  134. align=align,
  135. direction=None,
  136. features=None,
  137. language=None,
  138. stroke_width=0,
  139. stroke_fill=None,
  140. embedded_color=False)
  141. return img
  142. def resize(self, img: Image, command):
  143. if command["plugins_mode"] == "pixel":
  144. if command["base"] == "width":
  145. img = self.to_resize(img, width=command["value"])
  146. if command["base"] == "high":
  147. img = self.to_resize(img, height=command["value"])
  148. # 相对值
  149. if command["plugins_mode"] == "relative":
  150. base_im = command["base_im"]["im"]
  151. if command["base"] == "width":
  152. img = self.to_resize(img, width=img.width * command["percentage"] if not base_im else int(
  153. base_im.width * command["percentage"]))
  154. if command["base"] == "height":
  155. img = self.to_resize(img, width=img.height * command["percentage"] if not base_im else int(
  156. base_im.height * command["percentage"]))
  157. # by_im确保能塞进参考图内
  158. if command["base"] == "by_im":
  159. percentage = 1 if not command["percentage"] else command["percentage"]
  160. box_width, box_height = int(base_im.width * percentage), int(base_im.height * percentage)
  161. width, height = img.width, img.height
  162. if box_width / box_height < width / height:
  163. scale = box_width / width
  164. else:
  165. scale = box_height / height
  166. img = img.resize((int(width * scale), int(height * scale)))
  167. # img.show()
  168. return img
  169. def paste_img(self, img: Image, command):
  170. # 粘贴绝对像素
  171. base = "nw" if not command["pos"]["base"] else command["pos"]["base"]
  172. value = command["pos"]["value"]
  173. percentage = (0, 0) if not command["pos"]["percentage"] else command["pos"]["percentage"]
  174. if command["margins"]:
  175. top, down, left, right = command["margins"]
  176. else:
  177. top, down, left, right = 0, 0, 0, 0
  178. if percentage != (0, 0): # percentage 不按占比模式
  179. if base in ("nw", "wn", "wc", "cw", "nc", "cn", "center"):
  180. value = (int(img.width), int(img.height))
  181. if base in ("sw", "ws", "sc", "cs", "center"):
  182. value = (int(img.width), -1 * int(img.height))
  183. if base in ("ec", "ce"):
  184. value = (int(img.width), int(img.height))
  185. img_1 = command["img"]["im"]
  186. if command["pos"]["plugins_mode"] == "pixel":
  187. if base == "ec" or "ce":
  188. p_x = int(img.width - img_1.width) + value[0]
  189. p_y = value[1]
  190. if base == "nw" or "wn":
  191. deviation_x, deviation_y = 0, 0
  192. p_x, p_y = value
  193. if base == "cs" or "sc":
  194. p_x, p_y = value
  195. if base == "center":
  196. deviation_x, deviation_y = int((img.width - img_1.width) / 2), int((img.height - img_1.height) / 2)
  197. p_x = deviation_x + value[0] + left
  198. p_y = deviation_y + value[1] + top
  199. if base == "sw" or base == "ws":
  200. # deviation_x, deviation_y = 0, int((img.height - img_1.height))
  201. p_x = value[0] + left
  202. p_y = img.height - (img_1.height + value[1] + down)
  203. if base == "wc" or base == "cw":
  204. p_x = value[0] + left
  205. p_y = int((img.height - img_1.height) / 2) + value[1] + top
  206. try:
  207. img.paste(img_1, (p_x, p_y), img_1)
  208. except:
  209. img.paste(img_1, (p_x, p_y), img_1.convert("RGBA"))
  210. return img
  211. def crop_img(self, img: Image, command):
  212. base = "nw" if not command["pos"]["base"] else command["pos"]["base"]
  213. # print(base)
  214. value = command["pos"]["value"]
  215. percentage = command["pos"]["percentage"]
  216. if command["margins"]:
  217. top, down, left, right = command["margins"]
  218. else:
  219. top, down, left, right = 0, 0, 0, 0
  220. out_img_size = (value[2], value[3])
  221. # 默认填充色
  222. color_fill = command["color_fill"]
  223. if not color_fill:
  224. color_fill = (0, 0, 0)
  225. if command["pos"]["plugins_mode"] == "pixel":
  226. if base == "nw" or "wn":
  227. box = value
  228. if base == "sw" or base == "ws":
  229. # deviation_x, deviation_y = 0, int((img.height - img_1.height))
  230. box = (value[0], img.height - (value[1] + value[3]), value[2], value[3])
  231. print(box)
  232. if base == "se" or base == "es":
  233. box = (img.width - (value[0] + value[2]), img.height - (value[1] + value[3]), value[2], value[3])
  234. print(box)
  235. box = [box[0], box[1], box[0] + box[2], box[1] + box[3]]
  236. print("box", box)
  237. print("img.width", img.width)
  238. print("img.height", img.height)
  239. out_img = img.crop(box=box)
  240. print(out_img.size)
  241. # out_img.show()
  242. if box[0] < 0:
  243. out_img.paste(Image.new("RGB", (-1 * box[0], out_img.height), color_fill), (0, 0))
  244. # print(img.width, box)
  245. if box[2] > img.width:
  246. # print(box[2] - img.width, img.height)
  247. i = Image.new("RGB", (box[2] - img.width, out_img.height), color_fill)
  248. out_img.paste(i, (img.width - box[0], 0))
  249. if box[1] < 0:
  250. out_img.paste(Image.new("RGB", (img.width, -1 * box[1]), color_fill), (0, 0))
  251. if box[3] > img.height:
  252. out_img.paste(Image.new("RGB", (out_img.width, box[3] - img.height), color_fill),
  253. (0, img.height - box[1]))
  254. # bg_img = Image.new("RGB", out_img_size, color_fill)
  255. # if box[0] < 0:
  256. # x = -1 * box[0]
  257. # elif box[2] > img.width:
  258. # x = img.width - box[2]
  259. # else:
  260. # x = 0
  261. #
  262. # if box[1] < 0:
  263. # y = -1 * box[1]
  264. # elif box[2] > img.height:
  265. # y = img.height - box[1]
  266. # else:
  267. # y = 0
  268. # bg_img.paste(img, box=(x, y), )
  269. # print(box)
  270. # img = img.crop(box=box)
  271. # out_img.show()
  272. return out_img
  273. def radius(self, img: Image, command):
  274. # 单图圆角处理
  275. radii = command["value"]
  276. if radii > img.width / 2:
  277. radii = int(img.width / 2)
  278. if radii > img.height / 2:
  279. radii = int(img.height / 2)
  280. # 画圆(用于分离4个角)
  281. circle = Image.new('L', (radii * 2, radii * 2), 0) # 创建一个黑色背景的画布
  282. draw = ImageDraw.Draw(circle)
  283. draw.ellipse((0, 0, radii * 2, radii * 2), fill=255) # 画白色圆形
  284. # 原图
  285. img = img.convert("RGBA")
  286. w, h = img.size
  287. # 画4个角(将整圆分离为4个部分)
  288. alpha = Image.new('L', img.size, 255)
  289. _pos = command["circular_pos"]
  290. if not _pos:
  291. _pos = (1, 1, 1, 1)
  292. for index, i in enumerate(_pos):
  293. if index == 0 and i == 1:
  294. alpha.paste(circle.crop((0, 0, radii, radii)), (0, 0)) # 左上角
  295. if index == 1 and i == 1:
  296. alpha.paste(circle.crop((radii, 0, radii * 2, radii)), (w - radii, 0)) # 右上角
  297. if index == 2 and i == 1:
  298. alpha.paste(circle.crop((radii, radii, radii * 2, radii * 2)), (w - radii, h - radii)) # 右下角
  299. if index == 3 and i == 1:
  300. alpha.paste(circle.crop((0, radii, radii, radii * 2)), (0, h - radii)) # 左下角
  301. # alpha.show()
  302. img.putalpha(alpha) # 白色区域透明可见,黑色区域不可见
  303. return img
  304. def to_resize(self, _im, width=None, height=None):
  305. _im_x, _im_y = _im.size
  306. if width and height:
  307. if _im_x >= _im_y:
  308. height = None
  309. else:
  310. width = None
  311. if width:
  312. re_x = int(width)
  313. re_y = int(_im_y * re_x / _im_x)
  314. else:
  315. re_y = int(height)
  316. re_x = int(_im_x * re_y / _im_y)
  317. _im = _im.resize((re_x, re_y))
  318. return _im
  319. def add_pic(self, detailed_images):
  320. if not detailed_images:
  321. return
  322. page_len = 0
  323. for index, im in enumerate(detailed_images):
  324. page_len += im.height
  325. bg_im = Image.new("RGB", (im.width, page_len), (255, 255, 255))
  326. n = 0
  327. for index, im in enumerate(detailed_images):
  328. bg_im.paste(im, (0, n))
  329. n += im.height
  330. # bg_im.show()
  331. return bg_im
  332. def get_goods_pos(self, im, cut_image):
  333. # 保留多余内容
  334. old_x, old_y = im.size
  335. x1, y1, x2, y2 = cut_image.getbbox()
  336. goods_w, goods_h = x2 - x1, y2 - y1
  337. _w, _h = int(goods_w / 10), int(goods_h / 10) # 上下左右扩展位置
  338. new_x1, new_y1, new_x2, new_y2 = x1 - _w, y1 - _h, x2 + _w, y2 + _h # 防止超限
  339. new_x1 = 0 if new_x1 < 0 else new_x1
  340. new_y1 = 0 if new_y1 < 0 else new_y1
  341. new_x2 = old_x if new_x2 > old_x else new_x2
  342. new_y2 = old_y if new_y2 > old_y else new_y2
  343. # 剪切掉多余的内容,保留阴影
  344. im = im.crop((new_x1, new_y1, new_x2, new_y2)) # 切图
  345. return im
  346. def deal_one_pic(self, data=None, is_show=False):
  347. """
  348. 通用图片处理器
  349. 1、图片位置处理
  350. 输出拼接后的图片,以及拼接后商品所属位置
  351. """
  352. for command in data:
  353. if command["command"] == "paste_img":
  354. img1 = command["img1"]["im"]
  355. img2 = command["img2"]["im"]
  356. if "resize" in command["img2"]:
  357. if "width" in command["img2"]["resize"]:
  358. img2 = self.to_resize(img2, width=command["img2"]["resize"]["width"])
  359. if is_show:
  360. img2.show()
  361. img1.paste(img2, command["img2"]["pos"])
  362. if command["command"] == "image_crop":
  363. img1 = img1.crop(command["image_crop"])
  364. img = img1
  365. return img
  366. def deal_one_pic_2(self, orign_im, data=None):
  367. """
  368. 通用图片处理器
  369. 1、基于某原始图,进行加工,包括粘贴、单图处理等逻辑
  370. """
  371. # 单图缩放处理
  372. a = {"command": "resize",
  373. "plugins_mode": "relative", # pixel 相对(宽度、高度、其他参考图),或绝对像素
  374. "base_im": "im", # 参考基于其他图 PIL格式
  375. "base": "width", # base:pixel,width,height,by_long_side,by_short_side基于长边、基于短边 (基于短边时,则缩放到指定尺寸)
  376. "value": 649, # 固定值,如果为百分比,则为0
  377. "percentage": 0, } # 百分比
  378. # 单图圆角处理
  379. a = {"command": "radius", # radius
  380. "plugins_mode": "relative", # pixel 相对(短边),或绝对像素
  381. "circular_pos": (0, 1, 0, 1), # 从左上角顺时针,记录圆角数量
  382. "value": 649, # 固定值,如果为百分比,则为0
  383. "percentage": 0, } # 百分比
  384. # 单图处理成圆形
  385. a = {"command": "circular", # circular
  386. }
  387. # 单图旋转处理
  388. a = {"command": "rotate",
  389. "plugins_mode": "",
  390. "value": 649, # 固定值 顺时针
  391. }
  392. # 图片粘贴处理
  393. a = {
  394. "command": "paste_img",
  395. "img": {"im": "im"},
  396. "pos": {"plugins_mode": "relative", # pixel
  397. "base": "center", # nw,nc,ne,ec ... 各个方向参考点
  398. "value": (100, 100),
  399. "percentage": 0, },
  400. "margins": (0, 0, 0, 0), # 上下左右边距
  401. }
  402. # 图片剪裁处理
  403. a = {
  404. "command": "crop_img",
  405. "img": {"im": "im"},
  406. "plugins_mode": "relative", # pixel
  407. "base": "center", # nw,nc,ne,ec ... 各个方向参考点
  408. "box": (0, 0, 0, 0),
  409. }
  410. # 图片添加文字
  411. a = {
  412. "command": "add_text",
  413. "pos": {"plugins_mode": "relative", # pixel
  414. "base": "center", # nw,nc,ne,ec ... 各个方向参考点
  415. "value": (100, 100),
  416. "percentage": 0, },
  417. "font": "",
  418. "text": "",
  419. "align": "对齐方式",
  420. "direction": "文本的方向",
  421. "fill": "文字颜色",
  422. }
  423. # 图片渐变处理
  424. # https://blog.csdn.net/skying159/article/details/119532479
  425. def get_value(data_dict, key):
  426. return 1
  427. r_dict = {"nw": 0,
  428. }
  429. _r = 0
  430. for command in data:
  431. if command["command"] == "paste_img":
  432. img1 = command["img1"]["im"]
  433. img2 = command["img2"]["im"]
  434. if "resize" in command["img2"]:
  435. if "width" in command["img2"]["resize"]:
  436. img2 = self.to_resize(img2, width=command["img2"]["resize"]["width"])
  437. if "pos" in command["img2"]:
  438. base = command["img2"]["base"]
  439. value = command["img2"]["value"]
  440. if command["img2"]["plugins_mode"] == "relative":
  441. # 相对位置处理,居中比较特殊
  442. # 其他的先进行旋转与镜像,处理后,进行反向操作
  443. x, y = 0, 0
  444. if base == "center":
  445. x, y = int((img1.width - img2.width) / 2), int((img1.height - img2.height) / 2)
  446. if base == "nw" or base == "nw":
  447. pass
  448. w, h = img1.width * value[0], img1.height * value[0]
  449. img1.paste(img2, command["img2"]["pos"])
  450. if _r != 0:
  451. img1 = img1.rotate(_r * -1)
  452. continue
  453. if command["command"] == "image_crop":
  454. img1 = img1.crop(command["image_crop"])
  455. continue
  456. img = img1
  457. return img
  458. def get_overlay_pic(self, pil_img_1, pil_img_2, color):
  459. im_w, im_h = pil_img_1.size
  460. cv_im = cv2.cvtColor(np.asarray(pil_img_1), cv2.COLOR_RGB2BGR)
  461. # 创建一张纯色底图
  462. image_white = Image.new("RGB", (im_w, im_h), color)
  463. cv_image_white = cv2.cvtColor(np.asarray(image_white), cv2.COLOR_RGB2BGR)
  464. new_im = self.to_color_2(cv_image_white, cv_im)
  465. # new_im = cv2.addWeighted(new_im, 0.7, cv_im_2, 0.3, 0)
  466. # new_im = cv2.add(new_im, cv_im_2)
  467. new_im = Image.fromarray(cv2.cvtColor(new_im, cv2.COLOR_BGR2RGB))
  468. new_im.paste(pil_img_2, (0, 0), pil_img_2)
  469. return new_im
  470. def to_color_2(self, target, blend): # 正片叠底
  471. return np.array(np.multiply(target / 256, blend / 256) * 256, dtype=np.uint8)
  472. def to_color_1(self, img1, img2): # PS颜色模式
  473. img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2HSV)
  474. img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2HSV)
  475. img2[:, :, 0] = img1[:, :, 0]
  476. img2[:, :, 1] = img1[:, :, 1]
  477. res = cv2.cvtColor(img2, cv2.COLOR_HSV2BGR)
  478. return res
  479. if __name__ == '__main__':
  480. from collections import defaultdict
  481. def set_dict(one_dict):
  482. _ = defaultdict(str)
  483. for i, v in one_dict.items():
  484. if isinstance(v, dict):
  485. v = set_dict(v)
  486. _[i] = v
  487. return _
  488. def deal_one_pic(img: Image, data=None):
  489. """
  490. 通用图片处理器
  491. 1、基于某原始图,进行加工,包括粘贴、单图处理等逻辑
  492. """
  493. data = [set_dict(x) for x in data]
  494. for command in data:
  495. if command["command"] == "resize":
  496. img = OnePicDeal().resize(img, command)
  497. continue
  498. if command["command"] == "paste_img":
  499. img = OnePicDeal().paste_img(img, command)
  500. continue
  501. if command["command"] == "crop_img":
  502. img = OnePicDeal().crop_img(img, command)
  503. continue
  504. if command["command"] == "radius":
  505. img = OnePicDeal().radius(img, command)
  506. continue
  507. if command["command"] == "add_text":
  508. img = OnePicDeal().add_text(img, command)
  509. continue
  510. return img
  511. image_path = r"D:\MyDocuments\PythonCode\MyPython\red_dragonfly\deal_pics\auto_capture_V2\IPC\output\-秋季订货会夏季补充给葛明明\NUM24106316\阴影图处理\NUM24106316(3)_后跟_阴影.png"
  512. to_paste_img = Image.open(image_path)
  513. data = []
  514. bg_color = (246, 246, 246)
  515. # 单图缩放处理
  516. view = "后跟"
  517. data.append({"command": "resize",
  518. "plugins_mode": "pixel", # pixel 相对(宽度、高度、其他参考图),或绝对像素
  519. "base_im": {"im": ""}, # 参考基于其他图 PIL格式
  520. "base": "width", # base:pixel,width,height,by_im 基于长边、基于短边 (基于短边时,则缩放到指定尺寸)by_im确保能塞进参考图内
  521. "value": 1300 if view == "后跟" else 2200, # 固定值,如果为百分比,则为0
  522. "percentage": 0, }) # 百分比
  523. view_dict = {"俯视": (0, 0, 1100, 1200),
  524. "内里": (-1, -100, 1100, 1200),
  525. "后跟": (0, -100, 1100, 1200),
  526. "鞋底": (0, -100, 1100, 1200),
  527. }
  528. data.append({
  529. "command": "crop_img",
  530. "img": "",
  531. "pos": {"plugins_mode": "pixel", # pixel
  532. "base": "sw", # nw,nc,ne,ec ... 各个方向参考点
  533. "value": view_dict[view],
  534. },
  535. "color_fill": bg_color,
  536. })
  537. # 处理圆角
  538. data.append({"command": "radius", # radius
  539. "plugins_mode": "relative", # pixel 相对(短边),或绝对像素
  540. "circular_pos": (1, 0, 0, 1), # 从左上角顺时针,记录圆角数量
  541. "value": 100, # 固定值,如果为百分比,则为0
  542. "percentage": 0, }) # 百分比
  543. to_paste_img = deal_one_pic(to_paste_img, data)
  544. # print(to_paste_img.size)
  545. # 粘贴到白底图上
  546. img = Image.new("RGB", (1200, 1316), (255, 255, 255))
  547. data = []
  548. data.append({
  549. "command": "paste_img",
  550. "img": {"im": to_paste_img},
  551. "pos": {"plugins_mode": "pixel", # pixel relative
  552. "base": "wc", # nw,nc,ne,ec,... 各个方向参考点
  553. "value": (100, 0),
  554. "percentage": "",
  555. },
  556. "margins": (0, 0, 0, 0), # 上下左右边距
  557. })
  558. img = deal_one_pic(img, data)
  559. img.show()