当前位置: 首页>>代码示例>>Python>>正文


Python Image.compression_quality方法代码示例

本文整理汇总了Python中wand.image.Image.compression_quality方法的典型用法代码示例。如果您正苦于以下问题:Python Image.compression_quality方法的具体用法?Python Image.compression_quality怎么用?Python Image.compression_quality使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wand.image.Image的用法示例。


在下文中一共展示了Image.compression_quality方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: convert_pdf_to_img

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import compression_quality [as 别名]
def convert_pdf_to_img(blob, img_type="jpg", quality=75, resolution=200):
    """
    Converts PDF with multiple pages into one image.
    It needs the file content NOT the filename or ioBytes and returns the image content.
    Note: It has memory leak!!
    http://stackoverflow.com/a/26233785/1497443

    Example:

    with open('my.pdf', "r") as f:
        file_content = f.read()

    # import ipdb
    # ipdb.set_trace()
    hh = convert_pdf_to_jpg(file_content)

    with open('my.jpg', 'wb') as f:
        f.write(hh)
    """
    from wand.image import Image as WandImage
    from wand.color import Color as WandColor

    pdf = WandImage(blob=blob, resolution=resolution)

    pages = len(pdf.sequence)

    wimage = WandImage(width=pdf.width, height=pdf.height * pages, background=WandColor("white"))

    for i in xrange(pages):
        wimage.composite(pdf.sequence[i], top=pdf.height * i, left=0)

    if img_type == "jpg":
        wimage.compression_quality = quality

    return wimage.make_blob(img_type)
开发者ID:giussepi,项目名称:django-generic-utils,代码行数:37,代码来源:functions.py

示例2: resize_image

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import compression_quality [as 别名]
	def resize_image(self, img_path, size_config, size_name, dest_path, compress=False):
		#open image
		img = Image(filename=img_path)
		#transform using resize config
		img.transform(resize=size_config)
		'''
		exProcessor = ExifData()
		#rotate image if necessary
		if exProcessor.check_orientation(img) in [6, 7]:
			img.rotate(90)
			img.metadata['exif:Orientation'] = 1
		if exProcessor.check_orientation(img) in [6, 8]:
			img.rotate(-90)
			img.metadata['exif:Orientation'] = 1
		if exProcessor.check_orientation(img) in [3, 4]:
			img.rotate(180) 
			img.metadata['exif:Orientation'] = 1
		'''

		# Detect file extention
		fileName, fileExtension = os.path.splitext(img_path)

		#save img
		fileName = ''.join([fileName, '_', size_name, fileExtension])
		fileName = os.path.basename(fileName)
		fileName = os.path.abspath(os.path.join(dest_path, fileName))

		# Compress option?
		if compress:
			img.compression_quality = 70

		img.save(filename=fileName)

		return fileName
开发者ID:adzymaniac,项目名称:potongin,代码行数:36,代码来源:ImagickHelper.py

示例3: convertPdfToImage

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import compression_quality [as 别名]
def convertPdfToImage(file_loc):
	new_dir = file_loc.split(".")[0]
	if not os.path.exists(new_dir):
		os.makedirs(new_dir)
	doc = Image(filename=file_loc,resolution=300)
	doc.compression_quality = 20
	for i, page in enumerate(doc.sequence):
		with Image(page) as page_image:
			page_image.alpha_channel = False
			page_image.background_color = Color('white')
			save_location =  new_dir+"/img-{}.jpg".format(str(i).zfill(4))
			page_image.save(filename=save_location)
开发者ID:bryantravissmith,项目名称:DocumentOrganizer,代码行数:14,代码来源:documentsort.py

示例4: convertPdfToImage

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import compression_quality [as 别名]
def convertPdfToImage(file_loc,doc_id):
	print doc_id
	new_dir, file_ending = file_loc.split(".")
	if file_ending == 'pdf':
		if not os.path.exists(new_dir):
			os.makedirs(new_dir)
		doc = Image(filename=file_loc,resolution=300)
		doc.compression_quality = 20
		for i, page in enumerate(doc.sequence):
			with Image(page) as page_image:
				page_image.alpha_channel = False
				page_image.background_color = Color('white')
				save_location =  new_dir+"/img-{}.jpg".format(str(i).zfill(4))
				page_image.save(filename=save_location)
		t1 = threading.Thread(target=extractTextInImage,args=(file_loc,doc_id))
		t1.start()
		t2 = threading.Thread(target=updateImgMatchesForNewDoc,args=(doc_id,))
		t2.start()
开发者ID:bryantravissmith,项目名称:DocumentOrganizer,代码行数:20,代码来源:app.py

示例5: set_image

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import compression_quality [as 别名]
    def set_image(self, binary):
        self.binary = binary
        with Image(blob=self.binary, resolution=150) as img:
            self.extension = img.format.lower()
            flattened = Image(background=Color("white"),
                height=img.height, width=img.width)
            flattened.composite(img, left=0, top=0)
            flattened.format = "jpeg"
            flattened.compression_quality = 50

            thumbnail = flattened.clone()
            thumbnail.transform(resize='150x200>')
            self.thumbnail = thumbnail.make_blob()

            preview = flattened.clone()
            preview.gaussian_blur(radius=1, sigma=0.5)
            preview.transform(resize='612x792>')
            self.preview = preview.make_blob()
        self.save()
开发者ID:iandennismiller,项目名称:gthnk,代码行数:21,代码来源:page.py

示例6: pdf_to_image

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import compression_quality [as 别名]
def pdf_to_image(pdf, page=1, size=800, file_format='jpeg', quality=80):
    """Creates a image file from pdf file"""
    try:
        pdf.open()
    except Exception as e:
        raise e
    else:
        # do this while the pdf is open
        reader = PyPDF2.PdfFileReader(pdf, strict=False)
        writer = PyPDF2.PdfFileWriter()
        page_content = reader.getPage(page - 1)
        box = page_content.cropBox
        dims = [float(a - b) for a, b in zip(box.upperRight, box.lowerLeft)]
        scaleby = size / max(dims)
        dims = [int(d * scaleby) for d in dims]
        # resize_page(page_content, size)
        writer.addPage(page_content)
        outputStream = BytesIO()
        writer.write(outputStream)
        outputStream.seek(0)
    finally:
        pdf.close()
    # put content of page in a new image
    foreground = WandImage(
        blob=outputStream,
        format='pdf',
        resolution=int(1.6 * 72 * scaleby),
    )
    # make sure the color space is correct.
    # this prevents an occational bug where rgb colours are inverted
    foreground.type = 'truecolormatte'
    foreground.resize(*dims, 25)
    # white background
    background = WandImage(
        width=foreground.width,
        height=foreground.height,
        background=Color('white')
    )
    background.format = file_format
    background.composite(foreground, 0, 0)
    background.compression_quality = quality
    return background
开发者ID:universitas,项目名称:tassen,代码行数:44,代码来源:models.py

示例7: pages

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import compression_quality [as 别名]
    def pages(self):
        for page in range(self.file.numPages):
            img = WandImage(filename=self.path + ('[%s]' % page),
                resolution=self.config['wand_resolution'])
            img.compression_quality = self.config['wand_compression_quality']
            temp = NamedTemporaryFile(suffix='.jpg')
            # Passing temp as file kwargs does not work for some reason.
            # So we just pass the filename.
            img.save(filename=temp.name)

            # Reopen the image file as PIL object
            img = Image.open(temp.name)

            # Run tesseract
            tr = Tesseract()
            result = tr.ocr_image(img)

            temp.close()

            yield result
开发者ID:joashxu,项目名称:django-tesseract,代码行数:22,代码来源:utils.py

示例8: test_wand

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import compression_quality [as 别名]
def test_wand():
    image_data = Image(blob=s)
    image_data.compression_quality = 70
    is_gallery_card = False
    image_data_size = (image_data.width, image_data.height)

    image_size = (720, 720)
    if is_gallery_card:
        image_size = (720, 1120)

    if image_size != image_data_size:
        result = image_data.resize(image_size[0], image_size[1])

    with image_data.clone() as img:
        result = img = crop_image(img, (720, 472))

        # 공감전용 카드의 경우 댓글용 이미지를 생성하지 않는다.
        if not is_gallery_card:
            result = img.resize(460, 310)

    result = image_data.resize(360, 360)
    result = image_data.resize(132, 132)
    return result
开发者ID:nrise,项目名称:sipskia,代码行数:25,代码来源:benchmark.py

示例9: picture_save_api

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import compression_quality [as 别名]
def picture_save_api(request_file, original_file_size=(0, 0), original_file_type='jpeg', compress_file_size=(0, 0), compress_file_type='jpeg'):
    pic = Picture()
    pic.save()

    original_image = Image(file=urlopen(request_file))
    compress_image = original_image.clone()

    original_image.format = original_file_type
    compress_image.format = compress_file_type
    w, h = original_image.size

    original_width = w
    compress_width = w
    original_height = h
    compress_height = h

    if original_file_size[0] > 0:
        original_width = original_file_size[0]
    if original_file_size[1] > 0:
        original_height = original_file_size[1]

    if compress_file_size[0] > 0:
        compress_width = compress_file_size[0]
    if compress_file_size[1] > 0:
        compress_height = compress_file_size[1]

    original_image.resize(original_width, original_height)
    original_image.compression_quality = 60

    compress_image.resize(compress_width, compress_height)
    compress_image.compression_quality = 60

    pic.original_image.save(str(pic.id) + u'_o.' + original_file_type, ContentFile(original_image.make_blob()))
    pic.compress_image.save(str(pic.id) + u'_c.' + compress_file_type, ContentFile(compress_image.make_blob()))

    return pic
开发者ID:HunjaeJung,项目名称:omc-django,代码行数:38,代码来源:common.py

示例10: make_pages

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import compression_quality [as 别名]
def make_pages(request, document_pk):
    document = Document.objects.get(pk=document_pk)
    clear_pages(document)

    pdf_file_name = document.document_file._get_path()
    pdf_file = Image(filename=pdf_file_name, resolution=CONFIG['RESOLUTION'])
    tmp_dir = tempfile.mkdtemp()

    for page in pdf_file.sequence:
        page_number = page.index + 1
        page_img = Image(page)
        page_img.compression_quality = CONFIG['COMPRESSION_QUALITY']
        page_img_file_name = tmp_dir + \
            '/page{0}-{1}.jpg'.format(document_pk, page_number)
        page_img.save(filename=page_img_file_name)
        create_page(document, page_number, page_img_file_name)

    shutil.rmtree(tmp_dir)

    messages.add_message(
        request,
        messages.INFO,
        'Make pages for "{0}"'.format(document)
    )
开发者ID:lexsos,项目名称:avia35inner,代码行数:26,代码来源:utils.py

示例11: int

# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import compression_quality [as 别名]
			   boxWidth > minFontWidth and boxWidth < maxFontWidth:
				digit.resize(boxWidth, boxHeight, 'cubic')
				draw.composite(operator=operator, left=boxLeft, top=boxTop, width=boxWidth, height=boxHeight, image=digit)
			else:
				digit.resize(int(round(fontWidth*defaultFontScale)), int(round(fontHeight*defaultFontScale)), 'cubic')
				draw.composite(operator=operator, left=round((boxLeft+boxRight-fontWidth*defaultFontScale)/2.0), 
					       top=round((boxTop+boxBottom-fontHeight*defaultFontScale)/2.0), width=fontWidth*defaultFontScale, 
					       height=fontHeight*defaultFontScale, image=digit)

		
		characterIndex += 1
		col += 1
		if (octalDigitIndex % 6) == 4:
			col += 1
		if (octalDigitIndex % 6) == 5:
			col += 7
			characterIndex += 1
		boxIndex += 1
	# Next row, please
	row += 1
	if (index % 4) == 3:
		row += 1.2
draw(img)

# Create the output image.
img.format = 'jpg'
img.compression_quality = 25
img.save(filename=outImage)
print 'output =', outImage

开发者ID:avtobiff,项目名称:virtualagc,代码行数:31,代码来源:ProoferBox.py


注:本文中的wand.image.Image.compression_quality方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。