コード例 #1
0
ファイル: magick.py プロジェクト: BUDDGAF/FotoKilof
def get_image_size(file_in, gm_or_im):
    """
    identify width and height of picture
    input: file name
    output: width and height
    """

    width = 1
    height = 1
    size = ""
    file_info = common.spacja(os.path.join(tempfile.gettempdir(),
                                           "fotokilof_" + os.getlogin() \
                                           + "_image_info"))

    command = ' -format "%w\\n%h\\n%b" '
    command = command + common.spacja(file_in) + ' > '
    result = magick(command, "", file_info, gm_or_im + "identify")
    if result is not None:
        try:
            file = open(file_info, "r")
        except:
            log.write_log("get_image_size: cannot read file_info", "W")
        else:
            width = int(file.readline())
            height = int(file.readline())
            size = file.readline()
            file.close()
            try:
                os.remove(file_info)
            except:
                log.write_log("get_image_size: cannot remove image_info", "W")
    return (width, height, size)
コード例 #2
0
ファイル: magick.py プロジェクト: BUDDGAF/FotoKilof
def magick(cmd, file_in, file_out, command):
    """
    run imagemagick command.
    cmd - command for imagemagick
    file_in - fullname picture for processing
    file_out - fullname output picture
    command:
      convert, mogrify, composite, import - ImageMagick
      gm convert, gm mogrify, gm composite, gm import - GraphicsMagick
    """
    result = None
    if cmd != "":
        if file_in is not None:
            file_in = common.spacja(file_in)
            file_out = common.spacja(file_out)
            command = magick_command(command)
            command = command + " " + file_in  + " " + cmd + file_out
            log.write_log("Execute: " + command, "M")
            try:
                os.system(command)
            except:
                log.write_log("Errot in imagick: " + command, "E")
                result = None
            else:
                result = "OK"
        else:
            log.write_log("imagick: No file for imagick", "W")
            result = None
    else:
        result = None
    return result
コード例 #3
0
ファイル: magick.py プロジェクト: BUDDGAF/FotoKilof
def get_magick_version(gm_or_im):
    """ get version of *Magick """

    version = ""
    if gm_or_im is None:
        gm_or_im = ""

    file_version = common.spacja(os.path.join(tempfile.gettempdir(),
                                              "fotokilof_" + \
                                              os.getlogin() + "_version"))

    command = "-Version > "
    result = magick(command, "", common.spacja(file_version),
                    gm_or_im + "convert")
    if result is not None:
        try:
            file = open(file_version, "r")
        except:
            log.write_log("get_magick_version: cannot read file_version", "W")
        else:
            version_object = re.search("\\d+[.]\\d+([.]\\d+)*", file.readline())
            if version_object is not None:
                version = version_object[0]
            file.close()
            try:
                os.remove(file_version)
            except:
                log.write_log("get_magick_version: cannot remove file_version", "W")

    return version
コード例 #4
0
def preview_convert(file, dir_temp, command, size):
    """
    preview generation
    file - fullname image file
    dir_temp - fullname temporary directory
    command - additional command for imagemagick or space
    --
    return: fullname preview file and size
    """

    img = Image.open(file)
    width = str(img.size[0])
    height = str(img.size[1])

    file_preview = os.path.join(dir_temp, "preview.ppm")
    file = common.spacja(file)
    file_preview = common.spacja(file_preview)

    if platform.system() == "Windows":
        suffix = ".exe "
    else:
        suffix = " "
    command = "convert" + suffix + file + " -resize " + str(size) + "x" + str(size) + command + file_preview
    print(command)
    try:
        os.system(command)
    except:
        print("! Error in convert_preview: " + command)

    try:
        return {'filename': file_preview, 'width': width, 'height': height}
    except:
        print("! Error in convert_preview: return")
        return None
コード例 #5
0
def imagick(cmd, file_out, command):
    """
    run imagemagick command.
    cmd - command for imagemagick
    file_out - fullname picture for processing
    command: convert, mogrify, composite - imagemagick tools
    """
    result = None
    if cmd != "":
        if file_out is not None:
            if os.path.isfile(file_out):
                file_out = common.spacja(file_out)
                if platform.system() == "Windows":
                    suffix = ".exe "
                else:
                    suffix = " "
                command = command + suffix + cmd + " " + file_out
                print(command)
                try:
                    os.system(command)
                except:
                    print("! Error in imagick: " + command)
                    result = None
                else:
                    result = "OK"
            else:
                print("No file for processing")
        else:
            print("No file for imagick")
            result = None
    else:
        result = None
    return result
コード例 #6
0
def preview_histogram(file, dir_temp):
    """
    histogram generation
    file - fullname image file
    dir_temp - fullname temporary directory
    --
    return: fullname of histogram
    """

    file_histogram = common.spacja(os.path.join(dir_temp, "histogram.png"))
    file = common.spacja(file)

    if platform.system() == "Windows":
        suffix = ".exe "
    else:
        suffix = " "
    command = "convert" + suffix + file + " -colorspace Gray -define histogram:unique-colors=false histogram:" + file_histogram
    try:
        os.system(command)
        return file_histogram
    except:
        print("! Error in convert_histogram: " + command)
コード例 #7
0
ファイル: magick.py プロジェクト: BUDDGAF/FotoKilof
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