本文整理汇总了Python中wand.image.Image.make_blob方法的典型用法代码示例。如果您正苦于以下问题:Python Image.make_blob方法的具体用法?Python Image.make_blob怎么用?Python Image.make_blob使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wand.image.Image
的用法示例。
在下文中一共展示了Image.make_blob方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_thumb
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import make_blob [as 别名]
def create_thumb(self, img_path, date, text):
img = Image(filename=os.path.join(self.source_dir, img_path))
img.resize(self.thumb_size, self.thumb_size)
pixmap_on = QtGui.QPixmap()
pixmap_on.loadFromData(img.make_blob())
with Drawing() as draw:
draw.stroke_color = Color('white')
draw.stroke_width = 3
draw.line((0, 0), (self.thumb_size, self.thumb_size))
draw.line((0, self.thumb_size), (self.thumb_size , 0))
draw(img)
pixmap_off = QtGui.QPixmap()
pixmap_off.loadFromData(img.make_blob())
btn = IconButton(pixmap_on, pixmap_off, img_path, date, text)
btn.clicked.connect(self.thumb_clicked)
size = pixmap_on.size()
w, h = size.toTuple()
btn.setIconSize(size)
btn.setFixedSize(w+20, h+20)
self.scroll_vbox.addWidget(btn)
示例2: TestOverlayRoutes
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import make_blob [as 别名]
class TestOverlayRoutes(FlaskTestCase):
bucket = "wtf"
def setUp(self):
super(TestOverlayRoutes, self).setUp()
with Color('red') as bg:
self.image = Image(width=1920, height=1080, background=bg)
@mock.patch('giraffe.s3')
def test_image_overlay_relative_url(self, s3):
obj = mock.Mock()
obj.content = self.image.make_blob("png")
# s3 requests for 1. original image, 2. generated image with overlay, 3. overlay
s3.get.side_effect = [obj, make_httperror(404), obj]
r = self.app.get("/{b}/art.png?overlay=/{b}/tshirts/overlay.png&bg=451D74".format(b=self.bucket))
self.assertEqual(r.status_code, 200)
self.assertEqual(Image(blob=r.data).size, (1920, 1080))
@mock.patch('giraffe.s3')
def test_image_overlay_no_bg_color(self, s3):
# background isn't required, if your original image doesn't include transparency
# then you don't need the background color
obj = mock.Mock()
obj.content = self.image.make_blob("jpg")
# s3 requests for 1. original image, 2. generated image with overlay, 3. overlay
s3.get.side_effect = [obj, make_httperror(404), obj]
r = self.app.get("/{b}/art.jpg?overlay=/{b}/tshirts/overlay.png".format(b=self.bucket))
self.assertEqual(r.status_code, 200)
self.assertEqual(Image(blob=r.data).size, (1920, 1080))
@mock.patch('giraffe.requests')
@mock.patch('giraffe.s3')
def test_image_overlay_absolute_url(self, s3, requests):
obj = mock.Mock()
obj.content = self.image.make_blob("png")
s3.get.side_effect = [obj, make_httperror(404)]
requests.get.side_effect = [obj,]
r = self.app.get("/{}/art.png?overlay=https://cloudfront.whatever.org/tshirts/overlay.png&bg=451D74".format(self.bucket))
self.assertEqual(r.status_code, 200)
self.assertEqual(Image(blob=r.data).size, (1920, 1080))
@mock.patch('giraffe.s3')
def test_image_overlay_resize(self, s3):
obj = mock.Mock()
obj.content = self.image.make_blob("png")
s3.get.side_effect = [obj, make_httperror(404), obj]
r = self.app.get("/{b}/art.png?overlay=/{b}/tshirts/overlay.png&bg=451D74&w=100&h=100".format(b=self.bucket))
self.assertEqual(r.status_code, 200)
self.assertEqual(Image(blob=r.data).size, (100, 100))
示例3: _pdf_thumbnail
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import make_blob [as 别名]
def _pdf_thumbnail(filename):
img = WandImage(filename=filename + '[0]')
img.background_color = Color('white')
tw, th = get_thumbnail_size(img.height, img.width, 50, 50)
img.resize(tw, th)
rawData = img.make_blob('jpeg')
return base64.b64encode(rawData)
示例4: pdf2text
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import make_blob [as 别名]
def pdf2text(pdf_filename):
tool = pyocr.get_available_tools()[0]
lang = tool.get_available_languages()[1]
req_image = []
final_text = []
image_pdf = Image(filename=pdf_filename, resolution=300)
image_jpeg = image_pdf.convert('jpeg')
for img in image_jpeg.sequence:
img_page = Image(image=img)
req_image.append(img_page.make_blob('jpeg'))
for img in req_image:
txt = tool.image_to_string(
PI.open(io.BytesIO(img)),
lang=lang,
builder=pyocr.builders.TextBuilder()
)
final_text.append(txt)
return final_text
示例5: pdf2ocr
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import make_blob [as 别名]
def pdf2ocr(pdffile):
"""
Optical Character Recognition on PDF files using Python
see https://pythontips.com/2016/02/25/ocr-on-pdf-files-using-python/
:param pdffile: pdffile to be OCR'd
:return:
"""
from wand.image import Image
from PIL import Image as PI
import pyocr
import pyocr.builders
import io
tool = pyocr.get_available_tools()[0]
lang = tool.get_available_languages()[0] # [0] for english
req_image = []
final_text = []
print "Reading {0}".format(pdffile)
image_pdf = Image(filename=pdffile, resolution=300)
image_jpeg = image_pdf.convert("jpeg")
for img in image_jpeg.sequence:
img_page = Image(image=img)
print ("appending image")
req_image.append(img_page.make_blob("jpeg"))
print "Generating text"
for img in req_image:
txt = tool.image_to_string(PI.open(io.BytesIO(img)), lang=lang, builder=pyocr.builders.TextBuilder())
final_text.append(txt)
return final_text
示例6: convert_pdf_to_img
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import make_blob [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)
示例7: pdf2image
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import make_blob [as 别名]
def pdf2image(self,dest_width, dest_height):
RESOLUTION = 300
#blob = self.datas.decode('base64')
#raise Warning(self.base64_decode(self.datas))
#str = self.datas + '=' *(-len(self.datas)%4)
#img = Image(blob=self[0].datas.decode('base64'))
#img.resize(dest_width,dest_height)
#~ self[0].image = img.make_blob(format='jpg').encode('base64')
img = Image(blob=self[0].datas.decode('base64'),resolution=(RESOLUTION,RESOLUTION))
img.background_color = Color('white')
self[0].image = img.make_blob(format='jpg').encode('base64')
示例8: test_ico_masquerading_as_jpg_big
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import make_blob [as 别名]
def test_ico_masquerading_as_jpg_big(self, s3):
obj = mock.Mock()
image = Image(width=16, height=16)
obj.content = image.make_blob('ico')
obj.headers = {'content-type': 'image/jpeg'} # this is what S3 tells us =(
s3.get.side_effect = [obj, make_httperror(404)]
r = self.app.get("/{}/giant.jpg?w=400&h=400".format(self.bucket))
self.assertEqual(r.status_code, 200)
content_type = r.headers.get("content-type")
self.assertEqual(content_type, "image/jpeg")
self.assertEqual(Image(blob=r.data, format='jpeg').size, (400, 400))
示例9: render_pdf
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import make_blob [as 别名]
def render_pdf(self):
outpdf = PdfFileWriter()
for page in self.pages:
if page.extension == "pdf":
outpdf.addPage(PdfFileReader(StringIO.StringIO(page.binary)).getPage(0))
else:
img = Image(blob=page.binary, resolution=72)
img.format = "jpg"
img.format = "pdf"
outpdf.addPage(PdfFileReader(StringIO.StringIO(img.make_blob())).getPage(0))
pdf_page_buf = StringIO.StringIO()
outpdf.write(pdf_page_buf)
return pdf_page_buf.getvalue()
示例10: resize_if_params
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import make_blob [as 别名]
def resize_if_params(self, file_data):
""" If params width parameter is specified, resize the image
with wand and return the file data.
"""
width = self.request.params.get("width")
if width is None:
log.info("No width change")
return file_data
width = int(width)
log.debug("Change width to: %s", width)
new_img = Image(blob=file_data)
new_img.resize(width, 56)
return new_img.make_blob()
示例11: convert_pdf_to_jpeg
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import make_blob [as 别名]
def convert_pdf_to_jpeg(blob):
'''From stack overflow'''
pdf = Image(blob=blob)
pages = len(pdf.sequence)
print pages
image = Image(
width=pdf.width,
height=pdf.height * pages
)
return image.make_blob('jpg')
示例12: ExtractImg
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import make_blob [as 别名]
def ExtractImg(pdf_reader, n, out_path):
writer = PyPDF2.PdfFileWriter()
page = pdf_reader.getPage(n)
writer.addPage(page)
bytes = io.BytesIO()
writer.write(bytes)
bytes.seek(0)
wand_img = Image(file = bytes)
wand_img.format = 'jpg'
jpg_bin = wand_img.make_blob()
with open(out_path, 'wb') as temp_file:
temp_file.write(jpg_bin)
示例13: rasterizeImage
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import make_blob [as 别名]
def rasterizeImage(self):
if not os.path.isfile(self.getImgFilepath()):
print 'rasterize page:', self.n
# rasterize
wand_img = Image(file = self.bytes, resolution = int(IMAGE_WIDTH*DPI_TO_PX_RATIO/(self.pdf_page.mediaBox[3])))
width, height = wand_img.width, wand_img.height
wand_img.depth = 8
blob = wand_img.make_blob(format='RGB')
# convert wand_image to cv_image
img = np.zeros((height, width, 3), dtype = np.uint8)
for y in xrange(height):
for x in xrange(width):
img[y, x, 0] = struct.unpack('B', blob[3*(y*width+x)+2])[0]
img[y, x, 1] = struct.unpack('B', blob[3*(y*width+x)+1])[0]
img[y, x, 2] = struct.unpack('B', blob[3*(y*width+x)+0])[0]
cv2.imwrite(self.getImgFilepath(), img)
示例14: open_image
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import make_blob [as 别名]
def open_image(path, colors, width = 60, crop = None, gauge = [40,40]) :
# Find height ratio
height_ratio = gauge[1] / float(gauge[0])
# Open image, resize and posterize
with open(path) as fp :
# Open image
image = Image(file=fp)
# Crop
if crop != None :
image.crop(crop['x'], crop['y'], crop['w'] + crop['x'], crop['h'] + crop['y'])
# Resize to width and height ratio
resize(image, width, height_ratio)
# Get data
data = get_data(PImage.open(StringIO.StringIO(image.make_blob('ppm'))))
# Posterize image to fewer colors
return posterize(data, colors)
示例15: magick_crop
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import make_blob [as 别名]
def magick_crop(self, image_url=None, dataX=0, dataY=0, dataWidth=0, dataHeight=0, dataRotate=0, dataScaleX=1, dataScaleY=1, **kw):
if 'ir.attachment' in image_url:
# binary -> decode -> wand.image -> imagemagick -> make_blob() -> encode -> binary
img_attachment = request.env['ir.attachment'].browse(int(image_url.split('/')[4].split('_')[0]))
wand_img = Image(blob=getattr(img_attachment, 'datas').decode('base64'))
try:
wand_img.crop(int(dataX), int(dataY), width=int(dataWidth), height=int(dataHeight))
if dataScaleX and dataScaleY:
wand_img.resize(int(wand_img.width * float(dataScaleX)), int(wand_img.height * float(dataScaleY)))
if dataRotate:
wand_img.rotate(int(dataRotate))
img_attachment.write({ 'datas': wand_img.make_blob().encode('base64') })
except Exception as e:
return ': '.join(e)
return 'Magic Crop Completed!'
else:
return 'Please using attachment as image!'