コード例 #1
0
ファイル: server.py プロジェクト: martinciu/thumbnails
 def get(self):
     self.set_header("Content-Type", "image/jpeg")
     image = Image("../image.jpg")
     image.resize(Geometry(100, 100))
     blob = Blob()
     image.write(blob)
     self.write(blob.data)
コード例 #2
0
ファイル: pdf2img.py プロジェクト: hp910219/xml2word
def pdf2img(input_pdf, postfix='.png'):
    img = Image(input_pdf)
    img.density('300')
    size = "%sx%s" % (img.columns(), img.rows())
    output_img = Image(size, bgcolor)
    output_img.type = img.type
    output_img.composite(img, 0, 0,
                         PythonMagick.CompositeOperator.SrcOverCompositeOp)
    output_img.resize(str(img.rows()))
    output_img.magick('JPG')
    output_img.quality(75)
    output_jpg = input_pdf.replace(".pdf", postfix)
    if os.path.exists(output_jpg):
        os.remove(output_jpg)
    output_img.write(output_jpg)
コード例 #3
0
def pdf2img(input_pdf, postfix='.png', **kwargs):
    # print os.path.exists(input_pdf)
    img = Image(input_pdf)
    img.density('300')
    size = "%sx%s" % (img.columns(), img.rows())
    output_img = Image(size, bgcolor)
    output_img.type = img.type
    output_img.composite(img, 0, 0,
                         PythonMagick.CompositeOperator.SrcOverCompositeOp)
    output_img.resize(str(img.rows()))
    output_img.magick('JPG')
    output_img.quality(75)
    if 'out_path' in kwargs:
        output_jpg = kwargs['out_path']
    else:
        output_jpg = input_pdf + postfix
    if os.path.exists(output_jpg):
        os.remove(output_jpg)
    output_img.write(output_jpg)
コード例 #4
0
ファイル: grab.py プロジェクト: zeynelabidinertur/NewWords
def pdf_to_image():
    for pdf in [
            pdf_file for pdf_file in os.listdir(pdf_dir)
            if pdf_file.endswith(".pdf")
    ]:
        input_pdf = pdf_dir + "\\" + pdf + "[1]"
        img = Image()
        img.density('300')
        print input_pdf
        img.read(input_pdf)

        size = "%sx%s" % (img.columns(), img.rows())

        output_img = Image(size, bg_colour)
        output_img.type = img.type
        output_img.composite(img, 0, 0,
                             PythonMagick.CompositeOperator.SrcOverCompositeOp)
        output_img.resize(str(img.rows()))
        output_img.magick('JPG')
        output_img.quality(75)

        output_jpg = input_pdf.replace(".pdf", ".jpg")
        output_img.write(output_jpg)
コード例 #5
0
from PythonMagick import Image
from datetime import datetime

start_time = datetime.now()

pdf_dir = "/run/media/gru/Storage/Thesis-Latex/figures/vis-results"
bg_colour = "#ffffff"

for root, _, pdfs in os.walk(pdf_dir):
    for pdf in pdfs:
        if '.pdf' in pdf:
            input_pdf = os.path.join(root, pdf)
            print(input_pdf)
            img = Image()
            # img.density('300')
            img.read(input_pdf)

            size = "%sx%s" % (img.columns(), img.rows())

            output_img = Image(size, bg_colour)
            output_img.type = img.type
            output_img.composite(
                img, 0, 0, PythonMagick.CompositeOperator.SrcOverCompositeOp)
            output_img.resize(str(800))
            output_img.magick('PNG')
            output_img.quality(75)

            output_jpg = input_pdf.replace(".pdf", ".png")
            output_img.write(output_jpg)

print(datetime.now() - start_time)
コード例 #6
0
import os
import PythonMagick
import ghostscript
from PythonMagick import Image

         
pdf_dir = 'C:\\Users\\user\\Desktop\\fp' 
bg_colour = "#ffffff"

for pdf in [pdf_file for pdf_file in os.listdir(pdf_dir) if pdf_file.endswith(".pdf")]:

    input_pdf = pdf_dir + "\\" + pdf
    img = PythonMagick.Image(input_pdf)
    img.density('300')


    size = "%sx%s" % (img.columns(), img.rows())

    output_img = Image(size,bg_colour)
    output_img.type = img.type
    output_img.composite(img,0,0,PythonMagick.CompositeOperator.SrcOverCompositeOp)
    output_img.resize(str(img.rows()))
    output_img.magick('JPG')
    output_img.quality(100)


    output_jpg = input_pdf.replace(".pdf", ".jpg")
    output_img.write(output_jpg)

print "finish"
コード例 #7
0
ファイル: t.py プロジェクト: aviatorBeijing/ptpy
'strokePattern',
'strokeWidth', 'subImage', 'subRange', 
'swirl',
'syncPixels', 'textEncoding', 'texture', 'threshold', 
'throwImageException', 'tileName', 'totalColors', 
'transform', 'transformOrigin', 'transformReset', 
'transformRotation', 'transformScale', 'transformSkewX',
'transformSkewY', 'transparent', 'trim', 'type', 
'unregisterId', 'unsharpmask', 'verbose', 'view', 'wave', 
'write',
'writePixels',
'x11Display',
'xResolution',
'yResolution', 
'zoom']
'''

from PythonMagick import Image,Blob
#img = PythonMagick.Image("/home/insion/Pictures/k.jpg")

data=file('/home/insion/Pictures/o.jpg','rb').read()
img=Image(Blob(data))
img.resize('490')
img.write('k2k.jpg')
print("ok")

#k=fs.upload("/home/insion/Pictures/k.jpg")
#print(k)
#fs.delete("groupserver1/M00/00/00/wKhqTk_GwtDUaSWdAARGywFLfVc321.jpg")

コード例 #8
0
def modify_images(application_path):
    output_dirs = [
        path.join(application_path, "..", "512"),
        path.join(application_path, "..", "150")
    ]
    count_files = 0
    override = None

    FileUtilities.create_needed_folder(output_dirs)

    print()
    print(
        "\t--------------------------------------------------------------------"
    )
    print()
    print("\tErstelle die Bilder in der Größe \"512px\":")
    print()

    for filename in listdir(application_path):
        if not filename.endswith(".jpg"):
            continue

        if path.isfile(path.join(output_dirs[0], filename)):
            if override is None:
                override = TerminalUtilities.query_yes_no(
                    "\tSollen die bereits vorhandenen Bilder überschrieben werden?",
                    False)

            if not override:
                continue

        try:
            img = Image(path.join(application_path, filename))
            # noinspection PyArgumentList
            img.strip()
            # noinspection PyArgumentList
            img.trim()
            img.quality(80)
            img.resize("512x512>")
            img.write(path.join(output_dirs[0], filename))
        except RuntimeError as error:
            TerminalUtilities.error_handler(str(error), "RuntimeError")

        print("\t" + filename + "\t erfolgreich erstellt.")

        count_files += 1

    print()
    print("\tInsgesamt wurden " + str(count_files) +
          " Bilder in der Größe \"512px\" erzeugt.")
    print()
    print(
        "\t--------------------------------------------------------------------"
    )
    print()
    print("\tErstelle die Bilder in der Größe \"150px\":")
    print()

    count_files = 0

    for filename in listdir(output_dirs[0]):
        if not filename.endswith(".jpg"):
            continue

        if (not override) and (path.isfile(path.join(output_dirs[1],
                                                     filename))):
            continue

        img = Image(path.join(output_dirs[0], filename))
        img.resize("150x150>")
        img.write(path.join(output_dirs[1], filename))

        print("\t" + filename + "\t erfolgreich erstellt.")

        count_files += 1

    print()
    print("\tInsgesamt wurden " + str(count_files) +
          " Bilder in der Größe \"150px\" erzeugt.")