Common Functions

Here are some of the most common functions you might use when starting out with Blitline

Most Common:

  • resize_to_fit - Resize an image to fit within a bounding box
  • resize_to_fill - Resize an image to fill a bounding box (cropping off edges)
  • composite - Overlay (or underlay) an image on top of another image
  • annotate - Overlay text on top of an image
  • caption - Overaly (and autosize) text on top of an image


RESIZE TO FIT

Resize the image to fit within the specified dimensions while retaining the original aspect ratio. The image may be shorter or narrower than specified in the smaller dimension but will not be larger than the specified values

{
    "name": "resize_to_fit",
    "params": {
        "width": 40,
        "height": 40
    }
}

📘

Common English Translation

This is probably the crop you want if you need to rescale a photo down to a smaller size while keeping the same height to width ratio.

Required:

  • width : Width of desired image (optional if height defined)
  • height : Height of desired image (optional if width defined)

Optional:

  • only_shrink_larger : Don’t upsize image (defaults to false)
  • autosharpen : Automatically sharpens image after resize
  • gravity: Force edge to align



RESIZE TO FILL

Resize the image to fill the specified dimensions while retaining the aspect ratio of the original image. If necessary, crop the image in the larger dimension

{
    "name": "resize_to_fill",
    "params": {
        "width": 40,
        "height": 40
    }
}

📘

Common English Translation:

This is probably the crop you want if you need an image to fill a particular area. This is common for UI design where are the images need to be the same size (but the sources may be different widths and heights).

Required:

  • width : Width of desired image
  • height : Height of desired image

Optional:

  • only_shrink_larger : Don’t upsize image (defaults to false)
  • autosharpen : Automatically sharpens image after resize
  • gravity: Force edge to align



COMPOSITE

Composites one image onto another. This function takes a "src" value and will overlay that "src" image onto the existing image (in context).

{
    "name": "composite",
    "params": {
        "src" : "https://blitdoc.s3.amazonaws.com/pngs/tranparent_flower.png",
        "x" : 200,
        "y" : 0
    }
}

Required:

  • src : Url of image you wants composited with original image

Optional:

  • scale_to_fit : { “width” : width, “height” : height }, to automatically scale src specific size. Can also be percentage if prefixed with %
  • scale_to_match : “true” or “false” to automatically scale src to the same size as current image (defaults to false)
  • scale_to_fill : { “width” : width, “height” : height }, to automatically scale src to fill specific size. Can also be percentage if prefixed with %
  • as_mask : “true” or “false” to use src as a greyscale mask (defaults to false)
  • x : X offset of where to place image on original image
  • y : Y offset of where to place image on original image
  • gravity : Instead of x,y you could use gravity.
  • composite_op : How composite is to be applied. Defaults to “OverCompositeOp” (which means it will just be layed on top of original image). See “Composite Ops” section



ANNOTATE

Overlay text on top of an image

{
    "name":"annotate",
    "params":{
        "text":"my_text",
        "color":"#ffffff"
    }
}

Required:

  • text : Text to be placed on image

Optional:

  • x : X offset (defaults to 0)
  • y : Y offset (defaults to 0)
  • color : Color of text (defaults to ‘#ffffff’)
  • style : “normal” or “italic” or “oblique” (defaults to “normal”)
  • kerning : Distance between letters (defaults based on font)
  • font_weight : “bold” or “normal” (defaults to “bold”)
  • font : Font of text (defaults to ‘Arial’)
  • point_size : Size of text (defaults to 32)
  • stretch : Stretch value (Normal/Expanded/Condensed)
  • stroke : Color of stroke (defaults to “transparent”)
  • dropshadow _color : Adds a dropshadow of a specified color
  • dropshadow _offset : Pixels down/right for dropshadow, if dropshadow_color is set.
  • gravity : Placement of text (defaults to ‘CenterGravity’)

📘

See "Caption" if you want to autosize/wrap text to fit in a bounding box.




CAPTION

Caption will try to "autofit" text into a bounding box. Rescaling the text to fit and to wrap to make sure it's all within the define bounding box.

{
    "name": "caption",
    "params": {
        "text": "Sample Text That We Want To Wrap",
        "width": 400,
        "height": 900
    }
}

Required:

  • text : Text to be placed on image

Optional:

  • x : X offset (defaults to 0)
  • y : Y offset (defaults to 0)
  • width : Width of text area, either in pixels or percentage (ie. ‘90%’)
  • height : Height of text area, either in pixels or percentage (ie. ‘90%’)
  • color : Color of text (defaults to ‘#ffffff’)
  • font_weight : “bold” or “normal” (defaults to “bold”)
  • font : Font of text (defaults to ‘Arial’)
  • text_gravity : Where to align text, defaults to CenterGravity
  • point_size : Size of text
  • gravity : Placement of text (defaults to ‘CenterGravity’)

Did this page help you?