def add_rendered(self, image_id, data, width, height, crop): """ Adds a rendered image to the filesystem. @param media_id: ID of the image being rendered. @type media_id: String @param owner_username: User who's account the image is being rendered for. @type owner_username: String @param data: Actual binary data of the render @type data: String @param width: Requested width @type width: Integer @param height: Requested height @type height: Integer @param crop: Whether or not the image was cropped @type crop: Boolean """ try: image_id = validation.cast_integer(image_id, "image_id") validation.required(data, "data") if width: width = validation.cast_integer(width, "width") height = validation.cast_integer(height, "height") crop = validation.cast_boolean(crop, "crop") except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def get_render(self, image_id, width, height, crop): """ Gets a render for an image. @param owner_username: User who owns the image @type owner_username: String @param media_id: ID of the image @type media_id: String @param width: Width of the render @type width: Integer @param height: Height of the render @type height: Integer @param crop: Whether or not the render is cropped @type crop: Boolean """ try: image_id = validation.cast_integer(image_id, "image_id") width = validation.cast_integer(width, "width") height = validation.cast_integer(height, "height") crop = validation.cast_boolean(crop, "crop") except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def _make_media_path(self, media_id, host, username=None, width=None, height=None, crop=None): """ Makes a path to an image. @param media_id: ID of the image @type media_id: String @param host: Host that holds the image @type host: String @param username: User who modified the image (if applicable) @type username: String @param width: Width of the render @type width: Integer @param height: Height of the render @type height: Integer @param crop: Whether or not the render is cropped @type crop: Integer """ try: media_id = validation.media_id(media_id) validation.required(host, "host") if username: username = validation.username(username, "username") if width: width = validation.cast_integer(width, "width") height = validation.cast_integer(height, "height") crop = validation.cast_boolean(crop, "crop") except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def render_exists(self, image_id, width, height, crop): """ Determines whether a render exists for the specified user. @param owner_username: User who owns the image @type owner_username: String @param media_id: ID of the image @type media_id: String @param width: Width of the render @type width: Integer @param height: Height of the render @type height: Integer @param crop: Whether or not the render is cropped @type crop: Boolean """ try: image_id = validation.cast_integer(image_id, 'image_id') width = validation.cast_integer(width, 'width') height = validation.cast_integer(height, 'height') crop = validation.cast_boolean(crop, 'crop') except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def add_rendered(self, image_id, data, width, height, crop): """ Adds a rendered image to the filesystem. @param media_id: ID of the image being rendered. @type media_id: String @param owner_username: User who's account the image is being rendered for. @type owner_username: String @param data: Actual binary data of the render @type data: String @param width: Requested width @type width: Integer @param height: Requested height @type height: Integer @param crop: Whether or not the image was cropped @type crop: Boolean """ try: image_id = validation.cast_integer(image_id, 'image_id') validation.required(data, 'data') if width: width = validation.cast_integer(width, 'width') height = validation.cast_integer(height, 'height') crop = validation.cast_boolean(crop, 'crop') except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def _make_media_path(self, media_id, host, username=None, width=None, height=None, crop=None): """ Makes a path to an image. @param media_id: ID of the image @type media_id: String @param host: Host that holds the image @type host: String @param username: User who modified the image (if applicable) @type username: String @param width: Width of the render @type width: Integer @param height: Height of the render @type height: Integer @param crop: Whether or not the render is cropped @type crop: Integer """ try: media_id = validation.media_id(media_id) validation.required(host, 'host') if username: username = validation.username(username, 'username') if width: width = validation.cast_integer(width, 'width') height = validation.cast_integer(height, 'height') crop = validation.cast_boolean(crop, 'crop') except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def get_rendered_image(self, image_id, requested_width, requested_height, crop, fast, custom): """ Gets a rendered copy of an image from the database. If a render at the specified size doesn't exist, it is generated. If the size is not a custom size (ie. custom == true), it is stored in the database. @param owner_username: Username that owns the image. @type owner_username: String @param media_id: ID of the image being rendered. @type media_id: String @param requested_width: Width of the rendered image. @type requested_width: Integer @param requested_height: Height of the rendered image. @type requested_height: Integer @param crop: Whether or not the photo should be cropped to exact size. @type crop: Boolean @param custom: Whether or not this is a custom size @type custom: Boolean @return: Binary Image data @rtype: (Deferred) 8-bit string containing the image data """ try: image_id = validation.cast_integer(image_id, 'image_id') requested_width = validation.cast_integer(requested_width, 'requested_width') requested_height = validation.cast_integer(requested_height, 'requested_height') crop = validation.cast_boolean(crop, 'crop') fast = validation.cast_boolean(fast, 'fast') custom = validation.cast_boolean(crop, 'custom') except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)