image_pic_deal.py 24 KB

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