def _do_export(self, density, input_path, drawable): nonspecific = ".nonspecific." in input_path noflip = nonspecific or input_path.endswith(".noflip.svg") file_name = os.path.basename(os.path.splitext(input_path)[0].split(".")[0] + ".png") output_file_path = os.path.join(OUTPUT_PATH_PREFIX, drawable, file_name) px = int(DENSITIES[density] * self.dp) sh.rsvg_convert(input_path, "-a", h=px, o=output_file_path) return (output_file_path, noflip)
def _do_export(self, density, input_path, drawable): nonspecific = ".nonspecific." in input_path noflip = nonspecific or input_path.endswith(".noflip.svg") file_name = os.path.basename( os.path.splitext(input_path)[0].split(".")[0] + ".png") output_file_path = os.path.join(OUTPUT_PATH_PREFIX, drawable, file_name) px = int(DENSITIES[density] * self.dp) sh.rsvg_convert(input_path, "-a", h=px, o=output_file_path) return (output_file_path, noflip)
def _do_export(self, density, input_path, drawable): nonspecific = ".nonspecific." in input_path noflip = nonspecific or input_path.endswith(".noflip.svg") file_name = os.path.basename(os.path.splitext(input_path)[0].split(".")[0] + ".png") folder_path = os.path.join(OUTPUT_PATH_PREFIX, drawable) sh.mkdir("-p", folder_path) output_file_path = os.path.join(folder_path, file_name) output_precrush_path = output_file_path + "_" px = int(DENSITIES[density] * self.dp) sh.rsvg_convert(input_path, "-a", h=px, o=output_precrush_path) sh.pngcrush("-q", "-reduce", output_precrush_path, output_file_path) sh.rm(output_precrush_path) return output_file_path, noflip
def export(dp, density, filepath, drawable): noflip = '.nonspecific.' in filepath or filepath.endswith('.noflip.svg') filename = os.path.basename(filepath) new_filename = filename[:filename.index('.')] + '.png' folder_path = os.path.join(OUTPUT_PATH_PREFIX, drawable) sh.mkdir('-p', folder_path) output_file_path = os.path.join(folder_path, new_filename) output_precrush_path = output_file_path + '_' px = int(DENSITIES[density] * dp) sh.rsvg_convert(filepath, '-a', h=px, o=output_precrush_path) sh.pngcrush('-q', '-reduce', output_precrush_path, output_file_path) sh.rm(output_precrush_path) return output_file_path, noflip
def _do_export(self, density, input_path, drawable): nonspecific = ".nonspecific." in input_path noflip = nonspecific or input_path.endswith(".noflip.svg") file_name = os.path.basename(os.path.splitext(input_path)[0].split(".")[0] + ".png") folder_path = os.path.join(OUTPUT_PATH_PREFIX, drawable) sh.mkdir("-p", folder_path) output_file_path = os.path.join(folder_path, file_name) output_precrush_path = output_file_path + "_" px = int(DENSITIES[density] * self.dp) sh.rsvg_convert(input_path, "-a", h=px, o=output_precrush_path) sh.pngcrush("-q", "-reduce", output_precrush_path, output_file_path) sh.rm(output_precrush_path) return (output_file_path, noflip)
def create_label_page(ids, page_num): global x, y label_sheet = sg.SVGFigure('612', '792') # 8.5"x11" paper at 72dpi labels = [] # Convert the base label pdf to svg pdf2svg(label_pdf, 'output/label.svg') for nodeid in ids: nodeidstr = nodeid.replace(':', '') if QR_IN_USE: # Create the QR code img = qrcode.make(QR_CODE_STR.format(nodeid), image_factory=qrcode.image.svg.SvgPathImage, box_size=7, version=4, border=0) img.save('output/qr_{}.svg'.format(nodeidstr)) # Color the QR code with open('output/qr_{}.svg'.format(nodeidstr), 'r+') as f: svg = f.read() f.seek(0) svg = svg.replace('fill:#000000;', 'fill:{};'.format(QR_COLOR)) f.write(svg) # Create the node specific svg fig = sg.SVGFigure('{}px'.format(label_pixels_x), '{}px'.format(label_pixels_y)) rawlabel = sg.fromfile('output/label.svg') rawlabelr = rawlabel.getroot() if QR_IN_USE: qr = sg.fromfile('output/qr_{}.svg'.format(nodeidstr)) qrr = qr.getroot() # position correctly (hand tweaked) qrr.moveto(label_qr_pos_x, label_qr_pos_y, label_qr_scale) # position modifications based on text (x_mod, y_mod, nodeid) = position_label(nodeid) #txt = sg.TextElement(100,318, nodeid, size=28, font='Courier') txt = sg.TextElement(label_id_pos_x + x_mod, label_id_pos_y + y_mod, nodeid, size=label_id_font, font='Droid Sans', letterspacing=label_id_letterspacing, anchor='middle') if QR_IN_USE: fig.append([rawlabelr, qrr, txt]) else: fig.append([rawlabelr, txt]) fig.save('output/label_{}.svg'.format(nodeidstr)) if label_rotate: fig = sg.SVGFigure('{}px'.format(label_pixels_y), '{}px'.format(label_pixels_x)) dlabel = sg.fromfile('output/label_{}.svg'.format(nodeidstr)) dlabelr = dlabel.getroot() dlabelr.rotate(90, x=0, y=0) dlabelr.moveto(0, -1 * label_pixels_y) fig.append([dlabelr]) fig.save('output/label_{}.svg'.format(nodeidstr)) # labels.append(fig) # Convert the id specific image to pdf # sh.rsvg_convert('-f', 'pdf', '-o', 'label_{}.pdf'.format(nodeidstr), # 'label_{}.svg'.format(nodeidstr)) # Stamp the label with id specific image # pdftk(CASE_LABEL, 'stamp', 'unique_{}.pdf'.format(nodeidstr), 'output', # 'label_{}.pdf'.format(nodeidstr)) # pdf2svg('label_{}.pdf'.format(nodeidstr), 'label_{}.svg'.format(nodeidstr)) lbl = sg.fromfile('output/label_{}.svg'.format(nodeidstr)) lblr = lbl.getroot() pos = get_coordinates() lblr.moveto(pos[0], pos[1], 1) # position correctly (hand tweaked) if pos[2]: labels.append(lblr) label_sheet.append(labels) label_sheet.save('output/all_labels_{}.svg'.format(page_num)) sh.rsvg_convert('-f', 'pdf', '-d', '72', '-p', '72', '-o', 'output/all_labels_{}.pdf'.format(page_num), 'output/all_labels_{}.svg'.format(page_num)) # cleanup after yourself x = POSITION_START_X y = POSITION_START_Y for fl in glob.glob('output/label_*'): os.remove(fl)
# sh.rsvg_convert('-f', 'pdf', '-o', 'label_{}.pdf'.format(nodeidstr), # 'label_{}.svg'.format(nodeidstr)) # Stamp the label with id specific image # pdftk(CASE_LABEL, 'stamp', 'unique_{}.pdf'.format(nodeidstr), 'output', # 'label_{}.pdf'.format(nodeidstr)) # pdf2svg('label_{}.pdf'.format(nodeidstr), 'label_{}.svg'.format(nodeidstr)) lbl = sg.fromfile('label_{}.svg'.format(nodeidstr)) lblr = lbl.getroot() pos = get_coordinates(ltype) lblr.moveto(pos[0], pos[1], 1) # position correctly (hand tweaked) labels.append(lblr) label_sheet.append(labels) label_sheet.save('all_{}.svg'.format(ltype)) sh.rsvg_convert('-f', 'pdf', '-d', '72', '-p', '72', '-o', 'all_{}.pdf'.format(ltype), 'all_{}.svg'.format(ltype))
# pdf2svg('label_{}.pdf'.format(nodeidstr), 'label_{}.svg'.format(nodeidstr)) lbl = sg.fromfile('label_{}.svg'.format(nodeidstr)) # lbl.set_size(['{}pt'.format(label_pixels_x), '{}pt'.format(label_pixels_y)]) lblr = lbl.getroot() pos = get_coordinates() # print(pos) lblr.moveto(pos[0], pos[1], 1) # position correctly (hand tweaked) # lblr.set_size(['{}pt'.format(label_pixels_x), '{}pt'.format(label_pixels_y)]) labels.append(lblr) label_sheet.append(labels) # print(label_sheet.to_str()) base_name = 'triumvi_{}_{}'.format(sys.argv[1], sys.argv[2]) label_sheet.save('{}.svg'.format(base_name)) sh.rsvg_convert('-f', 'pdf', '-d', '72', '-p', '72', '-o', '{}.pdf'.format(base_name), '{}.svg'.format(base_name)) print('{}.pdf'.format(base_name))
def create_label_page(ids, page_num): global x,y label_sheet = sg.SVGFigure('612', '792') # 8.5"x11" paper at 72dpi labels = [] # Convert the base label pdf to svg pdf2svg(label_pdf, 'output/label.svg') for nodeid in ids: nodeidstr = nodeid.replace(':', '') if QR_IN_USE: # Create the QR code img = qrcode.make(QR_CODE_STR.format(nodeid), image_factory=qrcode.image.svg.SvgPathImage, box_size=7, version=4, border=0) img.save('output/qr_{}.svg'.format(nodeidstr)) # Color the QR code with open('output/qr_{}.svg'.format(nodeidstr), 'r+') as f: svg = f.read() f.seek(0) svg = svg.replace('fill:#000000;', 'fill:{};'.format(QR_COLOR)) f.write(svg) # Create the node specific svg fig = sg.SVGFigure('{}px'.format(label_pixels_x), '{}px'.format(label_pixels_y)) rawlabel = sg.fromfile('output/label.svg') rawlabelr = rawlabel.getroot() if QR_IN_USE: qr = sg.fromfile('output/qr_{}.svg'.format(nodeidstr)) qrr = qr.getroot() # position correctly (hand tweaked) qrr.moveto(label_qr_pos_x, label_qr_pos_y, label_qr_scale) # position modifications based on text (x_mod, y_mod, nodeid) = position_label(nodeid) #txt = sg.TextElement(100,318, nodeid, size=28, font='Courier') txt = sg.TextElement(label_id_pos_x+x_mod, label_id_pos_y+y_mod, nodeid, size=label_id_font, font='Droid Sans', letterspacing=label_id_letterspacing, anchor='middle') if QR_IN_USE: fig.append([rawlabelr, qrr, txt]) else: fig.append([rawlabelr, txt]) fig.save('output/label_{}.svg'.format(nodeidstr)) if label_rotate: fig = sg.SVGFigure('{}px'.format(label_pixels_y), '{}px'.format(label_pixels_x)) dlabel = sg.fromfile('output/label_{}.svg'.format(nodeidstr)) dlabelr = dlabel.getroot() dlabelr.rotate(90, x=0, y=0) dlabelr.moveto(0, -1*label_pixels_y) fig.append([dlabelr]) fig.save('output/label_{}.svg'.format(nodeidstr)) # labels.append(fig) # Convert the id specific image to pdf # sh.rsvg_convert('-f', 'pdf', '-o', 'label_{}.pdf'.format(nodeidstr), # 'label_{}.svg'.format(nodeidstr)) # Stamp the label with id specific image # pdftk(CASE_LABEL, 'stamp', 'unique_{}.pdf'.format(nodeidstr), 'output', # 'label_{}.pdf'.format(nodeidstr)) # pdf2svg('label_{}.pdf'.format(nodeidstr), 'label_{}.svg'.format(nodeidstr)) lbl = sg.fromfile('output/label_{}.svg'.format(nodeidstr)) lblr = lbl.getroot() pos = get_coordinates() lblr.moveto(pos[0], pos[1], 1) # position correctly (hand tweaked) if pos[2]: labels.append(lblr) label_sheet.append(labels) label_sheet.save('output/all_labels_{}.svg'.format(page_num)) sh.rsvg_convert('-f', 'pdf', '-d', '72', '-p', '72', '-o', 'output/all_labels_{}.pdf'.format(page_num), 'output/all_labels_{}.svg'.format(page_num)) # cleanup after yourself x = POSITION_START_X y = POSITION_START_Y for fl in glob.glob('output/label_*'): os.remove(fl)
anchor='left', size=label_url_font, font='Courier', letterspacing=label_url_letterspacing, color='black') fig.append([rawlabelr, txt, urltxt]) fig.save('label_{}.svg'.format(nodeidstr)) if label_rotate: fig = sg.SVGFigure('{}px'.format(label_pixels_y), '{}px'.format(label_pixels_x)) dlabel = sg.fromfile('label_{}.svg'.format(nodeidstr)) dlabelr = dlabel.getroot() dlabelr.rotate(90, x=0, y=0) dlabelr.moveto(0, -1*label_pixels_y) fig.append([dlabelr]) fig.save('label_{}.svg'.format(nodeidstr)) lbl = sg.fromfile('label_{}.svg'.format(nodeidstr)) lblr = lbl.getroot() pos = get_coordinates() lblr.moveto(pos[0], pos[1], 1) # position correctly (hand tweaked) labels.append(lblr) label_sheet.append(labels) base_name = 'edison-v3_{}_{}'.format(sys.argv[1], sys.argv[2]) label_sheet.save('{}.svg'.format(base_name)) sh.rsvg_convert('-f', 'pdf', '-d', '72', '-p', '72', '-o', '{}.pdf'.format(base_name), '{}.svg'.format(base_name)) print('{}.pdf'.format(base_name))