class Frame(ImageEffect): instantiable = True members_order = [ "edge_width", "edge_color", "vertical_padding", "horizontal_padding", "background" ] edge_width = schema.Integer(required=True, min=1, default=1) edge_color = schema.Color(required=True, default="#000000") vertical_padding = ImageSize(required=True, default="0") horizontal_padding = ImageSize(required=True, default="0") background = schema.Color(required=True, default="#000000") def apply(self, image): edge_color = resolve_color(self.edge_color) background = resolve_color(self.background) # Create the canvas width, height = image.size vertical_padding = ImageSize.resolve_size(self.vertical_padding, height) vertical_offset = self.edge_width + vertical_padding horizontal_padding = ImageSize.resolve_size(self.horizontal_padding, width) horizontal_offset = self.edge_width + horizontal_padding canvas = Image.new( "RGBA", (width + horizontal_offset * 2, height + vertical_offset * 2)) # Paint the border edge = self.edge_width if edge: canvas.paste(edge_color, None) # Paint the padding color canvas.paste(background, (edge, edge, edge + width + horizontal_padding * 2, edge + height + vertical_padding * 2)) # Paste the original image over the frame canvas.paste(image, (horizontal_offset, vertical_offset), image if image.mode in ("1", "L", "RGBA") else None) return canvas
class TwitterTimelineBlock(Block): instantiable = True type_group = "blocks.social" view_class = "cocktail.html.TwitterTimeline" members_order = [ "widget_id", "theme", "link_color", "width", "height", "related_accounts" ] widget_id = schema.String( required = True, member_group = "content" ) theme = schema.String( required = True, default = "light", enumeration = ("light", "dark"), member_group = "appearence" ) link_color = schema.Color( member_group = "appearence" ) width = schema.Integer( member_group = "appearence" ) height = schema.Integer( member_group = "appearence" ) related_accounts = schema.String( member_group = "tweet" ) def init_view(self, view): Block.init_view(self, view) view.widget_id = self.widget_id view.theme = self.theme view.link_color = self.link_color view.width = self.width view.height = self.height view.related = self.related_accounts
class Shadow(ImageEffect): instantiable = True offset = schema.Integer(required=True, default=5) padding = schema.Integer(required=True, default=8) color = schema.Color(required=True, default="#444444") iterations = 3 def apply(self, image): # Create the backdrop image -- a box in the background colour with a # shadow on it. total_width = image.size[0] + abs(self.offset) + 2 * self.padding total_height = image.size[1] + abs(self.offset) + 2 * self.padding back = Image.new("RGBA", (total_width, total_height)) # Place the shadow, taking into account the offset from the image shadow_left = self.padding + max(self.offset, 0) shadow_top = self.padding + max(self.offset, 0) color = resolve_color(self.color) back.paste(self.color, [ shadow_left, shadow_top, shadow_left + image.size[0], shadow_top + image.size[1] ]) # Apply the filter to blur the edges of the shadow. Since a small # kernel is used, the filter must be applied repeatedly to get a # decent blur. for n in range(self.iterations): back = back.filter(ImageFilter.BLUR) # Paste the input image onto the shadow backdrop image_left = self.padding - min(self.offset, 0) image_top = self.padding - min(self.offset, 0) back.paste(image, (image_left, image_top), image if image.mode in ("1", "L", "RGBA") else None) return back
) VideoPlayerSettings.add_member( schema.Boolean( "vimeo_portrait", required = True, default = True, listed_by_default = False, member_group = "vimeo" ) ) VideoPlayerSettings.add_member( schema.Color( "vimeo_color", listed_by_default = False, member_group = "vimeo" ) ) def player_initialization(player, settings, video): player.video_id = video.video_id player.width = settings.width player.height = settings.height player.vimeo_autoplay = settings.autoplay player.allow_fullscreen = settings.vimeo_allow_fullscreen player.vimeo_loop = settings.vimeo_loop player.vimeo_title = settings.vimeo_title player.vimeo_byline = settings.vimeo_byline player.vimeo_portrait = settings.vimeo_portrait player.vimeo_color = settings.vimeo_color
class Align(ImageEffect): instantiable = True members_order = [ "width", "height", "horizontal_alignment", "vertical_alignment", "background" ] width = ImageSize() height = ImageSize() horizontal_alignment = HorizontalAlignment(required=True, default="center") vertical_alignment = VerticalAlignment(required=True, default="center") background = schema.Color() def apply(self, image): source_width, source_height = image.size width = ImageSize.resolve_size(self.width, source_width) height = ImageSize.resolve_size(self.height, source_height) needs_halign = (source_width < width) needs_valign = (source_height < height) if needs_halign or needs_valign: if self.background: background = resolve_color(self.background) elif image.mode == "RGBA": background = (0, 0, 0, 0) else: background = (255, 255, 255) copy = Image.new( "RGBA" if background and len(background) == 4 else "RGB", (width, height), background) x = 0 y = 0 if needs_halign: if self.horizontal_alignment == "left": pass elif self.horizontal_alignment == "center": x = width / 2 - source_width / 2 elif self.horizontal_alignment == "right": x = width - source_width else: raise ValueError( "Align.horizontal_alignment expects 'left', 'center' " "or 'right', got %s" % self.horizontal_alignment) if needs_valign: if self.vertical_alignment == "top": pass elif self.vertical_alignment == "center": y = height / 2 - source_height / 2 elif self.vertical_alignment == "bottom": y = height - source_height else: raise ValueError( "Align.horizontal_alignment expects 'top', 'center' " "or 'bottom', got %s" % self.vertical_alignment) copy.paste(image, (x, y), image if image.mode == "RGBA" else None) return copy return image
class FacebookLikeBox(Block): instantiable = True type_group = "blocks.social" view_class = "cocktail.html.FacebookLikeBox" members_order = [ "fb_href", "fb_show_faces", "fb_stream", "fb_header", "fb_width", "fb_height", "fb_border_color", "fb_colorscheme" ] fb_href = schema.URL( required = True, member_group = "content" ) fb_show_faces = schema.Boolean( default = True, required = True, member_group = "appearence" ) fb_stream = schema.Boolean( default = False, required = True, member_group = "appearence" ) fb_header = schema.Boolean( default = False, required = True, member_group = "appearence" ) fb_width = schema.Integer( required = True, default = 292, member_group = "appearence" ) fb_height = schema.Integer( member_group = "appearence" ) fb_border_color = schema.Color( member_group = "appearence" ) fb_colorscheme = schema.String( required = True, default = "light", enumeration = ["light", "dark"], member_group = "appearence" ) def init_view(self, view): Block.init_view(self, view) view.href = self.fb_href view.show_faces = self.fb_show_faces view.stream = self.fb_stream view.header = self.fb_header view.width = self.fb_width view.height = self.fb_height view.border_color = self.fb_border_color view.colorscheme = self.fb_colorscheme