def _cnv_vbars(po_src_file, po_dst_file, po_cfg): """ Image conversion that pixelates the image using vertical bars. This function is a quick modification (only two lines modified from _cnv_mosaic: In _cnv_mosaic: [1] ti_pic_size_final = geom.max_rect_in(po_cfg.ti_size, po_cfg.tf_aspect) [2] u_cmd += u'-ordered-dither o2x2 -resize %ix%i! ' % (ti_pic_size_small[0], ti_pic_size_small[1]) [3] ti_pic_size_small = geom.max_rect_in((i_pixels, i_pixels), po_cfg.tf_aspect) Here: [1] ti_pic_size_final = po_cfg.ti_size [2] u_cmd += u'-ordered-dither o2x2 -resize %ix%i! ' % (ti_pic_size_small[1], 1) [3] ti_pic_size_small = (i_pixels, 1) So, don't edit this function directly for any major change. :param po_src_file: :param po_dst_file: :param po_cfg: :return: """ # Variables preparation #---------------------- i_colors = int(po_cfg.tf_options[0]) i_pixels = int(po_cfg.tf_options[1]) ti_pic_size_final = po_cfg.ti_size ti_pic_size_small = (i_pixels, 1) ti_pic_size_big = geom.min_rect_out(ptf_rec_in=ti_pic_size_final, pf_rot_out=po_cfg.f_rotation) # Command line build #------------------- u_cmd = u'convert ' u_cmd += u'"%s" ' % cmd.sanitize_path(po_src_file.u_path) # Pixelation u_cmd += u'-colors %i ' % i_colors u_cmd += u'-ordered-dither o2x2 -resize %ix%i! ' % (ti_pic_size_small[0], ti_pic_size_small[1]) u_cmd += u'-modulate 100,120,100 ' # Color overlay u_cmd += u'-colorspace rgb ' u_cmd += u'\( -clone 0 -fill "#%s" -colorize 100%% \) -compose Over -composite ' % po_cfg.u_color # Resize (1 extra pixel added in each border to avoid border color seen because rounding error) u_cmd += u'-filter point -resize %ix%i! ' % (ti_pic_size_big[0] + 2, ti_pic_size_big[1] + 2) #u_cmd += u'-background red ' # Rotation u_cmd += u'-rotate %f +repage ' % po_cfg.f_rotation # Crop u_cmd += u'-gravity Center ' u_cmd += u'-crop %ix%i+0+0 +repage ' % (ti_pic_size_final[0], ti_pic_size_final[1]) # Final output u_cmd += u'"%s"' % cmd.sanitize_path(po_dst_file.u_path) # Command line execution #----------------------- du_output = cmd.execute(u_cmd) if du_output['u_stderr']: print du_output['u_stderr'] # Coordinates calculation after image manipulation #------------------------------------------------- o_img_transformation = ImgKeyCoords() o_img_transformation.ti_size = _img_get_size(po_dst_file.u_path) # Debug code to overlay image regions #_draw_coordinates(po_dst_file, o_img_transformation) return o_img_transformation
def _cnv_mosaic(po_src_file, po_dst_file, po_cfg): # Variables preparation #---------------------- i_colors = int(po_cfg.tf_options[0]) i_pixels = int(po_cfg.tf_options[1]) ti_pic_size_final = po_cfg.ti_size # The shortest side of original picture will contain the desired number of pixels and the longest one the pixels # needed to keep the original aspect ratio. if po_cfg.tf_aspect[0] < po_cfg.tf_aspect[1]: i_width_small = i_pixels i_height_small = int(round(po_cfg.tf_aspect[1] / po_cfg.tf_aspect[0] * i_pixels)) else: i_height_small = i_pixels i_width_small = int(round(po_cfg.tf_aspect[0] / po_cfg.tf_aspect[1] * i_pixels)) ti_pic_size_small = (i_width_small, i_height_small) #print 'SRC ASPECT: %s' % str(po_cfg.tf_aspect) #print 'SMALL SIZE: %s' % str(ti_pic_size_small) ti_pic_size_big = geom.min_rect_out(ptf_rec_in=ti_pic_size_final, pf_rot_out=po_cfg.f_rotation, ptf_asp_out=po_cfg.tf_aspect) # Command line build #------------------- u_cmd = u'convert ' u_cmd += u'"%s" ' % cmd.sanitize_path(po_src_file.u_path) # Pixelation u_cmd += u'-colors %i ' % i_colors u_cmd += u'-ordered-dither o2x2 -resize %ix%i! ' % (ti_pic_size_small[0], ti_pic_size_small[1]) u_cmd += u'-modulate 100,120,100 ' # Color overlay u_cmd += u'-colorspace rgb ' u_cmd += u'\( -clone 0 -fill "#%s" -colorize 100%% \) -compose Over -composite ' % po_cfg.u_color # Resize (1 extra pixel added in each border to avoid border color seen because rounding error) u_cmd += u'-filter point -resize %ix%i! ' % (ti_pic_size_big[0] + 2, ti_pic_size_big[1] + 2) #u_cmd += u'-background red ' # Rotation u_cmd += u'-rotate %f +repage ' % po_cfg.f_rotation # Crop u_cmd += u'-gravity Center ' u_cmd += u'-crop %ix%i+0+0 +repage ' % (ti_pic_size_final[0], ti_pic_size_final[1]) # Final output u_cmd += u'"%s"' % cmd.sanitize_path(po_dst_file.u_path) # Command line execution #----------------------- du_output = cmd.execute(u_cmd) if du_output['u_stderr']: print du_output['u_stderr'] # Coordinates calculation after image manipulation #------------------------------------------------- o_img_transformation = ImgKeyCoords() o_img_transformation.ti_size = _img_get_size(po_dst_file.u_path) # Debug code to overlay image regions #_draw_coordinates(po_dst_file, o_img_transformation) return o_img_transformation