本文整理汇总了Python中wand.image.Image.alpha_channel方法的典型用法代码示例。如果您正苦于以下问题:Python Image.alpha_channel方法的具体用法?Python Image.alpha_channel怎么用?Python Image.alpha_channel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wand.image.Image
的用法示例。
在下文中一共展示了Image.alpha_channel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload_from_web
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import alpha_channel [as 别名]
def upload_from_web(self, request, pk=None):
from wand.image import Image
from wand.color import Color
from wand import exceptions as wand_exceptions
from apps.group.models import CourseGroup, CourseGroupMember
chatroom = self.get_object()
try:
chatroom_member = ChatroomMember.objects.get(chatroom=chatroom, user=request.user)
except ChatroomMember.DoesNotExist:
# Create the course group member (is past)
course_group = CourseGroup.objects.get(chatroom=chatroom)
course_group_member = CourseGroupMember.objects.create(course_group=course_group, student=request.user.student, is_past=True)
# Create the chatroom member (is past)
chatroom_member = ChatroomMember.objects.create(user=request.user, chatroom=chatroom, is_past=True)
name = request.data.get('name')
is_anonymous = int(request.data.get('is_anonymous', False))
tag = Tag.objects.get(pk=int(request.POST.get('tag_id')))
new_upload = Upload.objects.create(chatroom_member=chatroom_member, chatroom=chatroom, name=name, tag=tag, is_anonymous=is_anonymous)
all_urls = ""
for fp in request.FILES:
uploadedFile = request.data.get(fp)
if uploadedFile.content_type == "application/pdf":
image_pdf = Image(file=uploadedFile, resolution=250, background=Color("white"))
image_jpeg = image_pdf.convert('jpeg')
count = 0
for single_img in image_jpeg.sequence:
img = Image(image=single_img, resolution=250)
temp = tempfile.TemporaryFile()
img.alpha_channel = False
img.save(file=temp)
url = new_upload.upload_file(temp)
temp.close()
all_urls = all_urls + url + "\n"
count += 1
if count >= 25:
break
break
url = new_upload.upload_file(uploadedFile)
all_urls = all_urls + url + "\n"
activity_type = ChatroomActivityType.objects.get_activity_type(ChatroomActivityTypeManager.UPLOAD)
activity = ChatroomActivity.objects.create(chatroom=chatroom, chatroom_activity_type=activity_type, activity_id=new_upload.pk)
new_upload.send_created_notification(activity, request, True)
# post to slack TODO add detail
message = request.user.email + " uploaded files to " + chatroom.name + ":\n[" + str(new_upload.id) + "] " + all_urls
slack_utils.send_simple_slack_message(message)
return Response(200)
示例2: hash_image_file
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import alpha_channel [as 别名]
def hash_image_file(filepath):
"""
Get pHash dct hash of local image file.
:param filepath: path to image file
:return: perceptual hash of image file, or None on error
"""
if not os.path.exists(filepath):
print("File {0} does not exist".format(filepath))
return None
img = Image(filename=filepath)
if not img.alpha_channel:
return dct_hash(filepath)
# strip alpha channel and write to temp file before hashing
_, without_alpha = mkstemp()
img.alpha_channel = False
img.save(filename=without_alpha)
h = dct_hash(without_alpha)
os.remove(without_alpha)
return h
示例3: process_image
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import alpha_channel [as 别名]
def process_image(raw_content):
alpha = None
img = Image(file=StringIO(raw_content))
if img.alpha_channel:
img_png = img.convert('png')
img_png.type = 'truecolormatte'
img.alpha_channel = False
alpha = StringIO()
img_png.save(file=alpha)
alpha.seek(0)
if img.type == 'colorseparation' or img.colorspace == 'lab':
base_img = img.convert('tiff')
else:
base_img = img.convert('png')
# base_img = img.convert('tiff')
base = StringIO()
base_img.save(file=base)
base.seek(0)
return base, alpha
示例4: Image
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import alpha_channel [as 别名]
pages = 1
image = Image(
width = imageFromPdf.width,
height = imageFromPdf.height*pages
)
for i in range(pages):
image.composite(
imageFromPdf.sequence[i],
top = imageFromPdf.height * i,
left = 0
)
image.resize(250,250)
image.alpha_channel = False
image.format = 'png'
print(image.size)
image.background_color = Color('pink')
image.type = 'grayscale'
image.caption = file.split('.')[0]
image.save(filename = fileDirectory+file.split('.')[0]+".png")
image.clear()
image.close()
#display(image)
示例5: Image
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import alpha_channel [as 别名]
# Read in the input image ... i.e., the B&W octal page.
img = Image(filename=backgroundImage)
if invert:
img.negate()
backgroundWidth = img.width
backgroundHeight = img.height
if swapColors:
print 'Swapping colors'
for i in range(0, 8):
replaceColorsInImage(images[i], Color(matchColor), Color(scanColor))
replaceColorsInImage(img, Color(scanColor), Color(matchColor))
# Make certain conversions on the background image.
img.type = 'truecolor'
img.alpha_channel = 'activate'
# Determine the range of binsource lines we need to use. We're guaranteed
# they're all in the binsource lines[] array.
if bankNumber < 4:
bankNumber = bankNumber ^ 2
startIndex = bankNumber * 4 * 8 * 4 + pageInBank * 4 * 8
endIndex = startIndex + 4 * 8
draw = Drawing()
evilColor = Color("#FF00FF")
extraColor = Color("#FF8000")
draw.stroke_color = evilColor
draw.stroke_width = 4
draw.fill_opacity = 0