def check_imagemagick(suffix): """ Check if ImageMagick is avaialble""" if shutil.which('convert' + suffix): result = "OK" if shutil.which('mogrify' + suffix): result = "OK" if shutil.which('composite' + suffix): result = "OK" if shutil.which('identify' + suffix): result = "OK" if mswindows.windows() == 0: if shutil.which('import' + suffix): result = "OK" else: result = None else: result = None else: result = None else: result = None else: result = None return result
def check_magick(): """ What is available: ImageMagick, Graphick Magick or none """ if mswindows.windows() == 1: suffix = ".exe" else: suffix = "" if check_imagemagick(suffix) is not None: version = "IM" if mswindows.windows() == 1: result = "magick " else: result = "" elif check_graphicsmagick(suffix) is not None: version = "GM" result = "gm " else: version = "" result = None return (result, version)
def check_magick(): """ What is available: ImageMagick, Graphick Magick or none, and version """ if mswindows.windows() == 1: suffix = ".exe" else: suffix = "" if check_imagemagick(suffix) is not None: version = "IM" if mswindows.windows() == 1: result_gm = "magick " else: result_gm = "" elif check_graphicsmagick(suffix) is not None: version = "GM" result_gm = "gm " else: version = "" result_gm = None version = version + ':' + get_magick_version(result_gm) return (result_gm, version)
def copy_to_clipboard(file_in): """ Copy results into clipboard https://stackoverflow.com/questions/34322132/copy-image-to-clipboard Copy to clipboard works for Windows only """ if mswindows.windows() == 1: image = Image.open(file_in) output = BytesIO() image.convert("RGB").save(output, "BMP") data = output.getvalue()[14:] output.close() win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardData(win32clipboard.CF_DIB, data) win32clipboard.CloseClipboard()
def spacja(file_path): """ escaping space and special char in pathname """ if len(file_path) == 0: result = file_path else: file_path = os.path.normpath(file_path) if mswindows.windows() == 1: czy_spacja = re.search(" ", file_path) if czy_spacja is not None: file_path = '"' + file_path + '"' else: path = os.path.splitext(file_path) path_splitted = path[0].split('/') path_escaped = [] for i in path_splitted: path_escaped.append(re.escape(i)) file_path = '/'.join(path_escaped) + path[1] result = file_path return result
def list_of_images(cwd): """ jpg, png and tiff images in cwd return sorted list """ list_of_files = os.listdir(cwd) file_list = [] patterns = ("*.JPG", "*.JPEG", "*.PNG", "*.TIF", "*.TIFF") if mswindows.windows() == 0: patterns = patterns + ("*.jpg", "*.jpeg", "*.png", "*.tif", "*.tiff") for pattern in patterns: for file in list_of_files: if fnmatch.fnmatch(file, pattern): file_list.append(file) file_list.sort() return file_list
def magick_command(command): """ make [Graphics|Image]Magick independent command: it depends: - ImageMagick: - Unix: convert, mogrify, composite - Windows: magick.exe convert, magick.exe mogrify, magick.exe composite - GraphicsMagick: - Unix: gm convert, gm mogrify, gm composite - Windows: gm.exe convert, gm.exe mogrify, gm.exe composite """ if mswindows.windows() == 1: suffix = ".exe " else: suffix = " " tool = command.split() tool.insert(1, suffix) tool.extend(' ') result = "".join(tool) return result
def display_image(file_in, gm_or_im): """ display image """ file_in = common.spacja(file_in) if mswindows.windows() == 1: display = 'explorer' # this is the best idea for Windows ampersand = '' else: display = gm_or_im + "display" ampersand = ' &' command = magick_command(display) command = command + " " + file_in + ampersand log.write_log("Execute: " + command, "M") try: os.system(command) except: log.write_log(" Error in imagick: " + command, "E") result = None else: result = "OK" return result
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. function for GUI """ from io import BytesIO from PIL import Image import mswindows if mswindows.windows() == 1: import win32clipboard def copy_to_clipboard(file_in): """ Copy results into clipboard https://stackoverflow.com/questions/34322132/copy-image-to-clipboard Copy to clipboard works for Windows only """ if mswindows.windows() == 1: image = Image.open(file_in) output = BytesIO() image.convert("RGB").save(output, "BMP") data = output.getvalue()[14:]