def create_empty_image(output=None, resolution_x=1920, resolution_y=1080, background_color=None): """ Creates an empty image and stores it in the given path :param output: str :param resolution_x: int :param resolution_y: int :param background_color: list(int, int, int) :return: str or QImage """ if background_color is None: background_color = [0, 0, 0] pixmap = QPixmap(resolution_x, resolution_y) pixmap.fill(QColor(*background_color)) if output: output_path = path_utils.clean_path(output) output_dir = os.path.dirname(output_path) if os.access(output_dir, os.W_OK): pixmap.save(output_path) return output_path return QImage(pixmap)
def export_shader_swatch_as_image(shader_name, export_path=None, render_size=100, swatch_width=100, swatch_height=100, format='png', get_pixmap=False): """ Export shader swatch as image :param shader_name: str :param export_path: str :param render_size: int :param swatch_width: int :param swatch_height: int :param format: str :return: variant, None || str """ swatch = get_shader_swatch(shader_name=shader_name, render_size=render_size, swatch_width=swatch_width, swatch_height=swatch_height) swatch_pixmap = QPixmap(swatch.size()) swatch.render(swatch_pixmap) export_path = os.path.join(export_path, shader_name + '.' + format) swatch_pixmap.save(export_path) if get_pixmap: # swatch.deleteLater() # swatch = None return swatch_pixmap if export_path is None: return None if not os.path.exists(export_path): return None export_path = os.path.join(export_path, shader_name + '.' + format) swatch_pixmap.save(export_path) # swatch.deleteLater() # swatch = None return export_path