6.1.0 • Published 3 years ago

@titanium-sdk/ti.imagefactory v6.1.0

Weekly downloads
6
License
ISC
Repository
github
Last release
3 years ago

Titanium ImageFactory Module

Ti.ImageFactory provides a set of image transformation functions including the ability to scale, crop, and compress images. Additionally, this module offers the functionality of adding alpha channels and transparent borders.

Getting Started

View the Using Titanium Modules document for instructions on getting started with using this module in your application.

Accessing the Ti.ImageFactory Module

To access this module from JavaScript, you would do the following:

const ImageFactory = require('ti.imagefactory');

Methods

imageWithRotation(blob, options)

Creates a new image by creating a copy of the given image that is rotated.

Arguments

  • Image blobblob: Image to transform
  • Optionsdictionary: A dictionary specifying the options for the transformation
    • degreesint: The degrees to rotate the image

imageWithAlpha(blob, options)

Creates a new image by creating a copy of the given image, adding an alpha channel if it doesn't already have one.

Arguments

  • Image blobblob: Image to transform
  • Optionsdictionary: A dictionary specifying the options for the transformation
    • iOS: Currently there are no properties for this method -- specify an empty dictionary
    • Android: format int: The output format: ImageFactory.JPEG, ImageFactory.PNG, ImageFactory.WEBP (default: ImageFactory.JPEG)
    • Android: qualityfloat: The quality of the resulting JPEG or WebP image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality). (default: 0.7)

imageWithTransparentBorder(blob, options)

Creates a new image by creating a copy of the given image, adding a transparent border of the given size around its edges. The size of the image will be expanded by the specified border size.

Arguments

  • Image blobblob: Image to transform
  • Optionsdictionary: A dictionary specifying the options for the transformation
    • borderSizeint: The size of the border (default: 1)
    • Android: format int: The output format: ImageFactory.JPEG, ImageFactory.PNG, ImageFactory.WEBP (default: ImageFactory.JPEG)
    • Android: qualityfloat: The quality of the resulting JPEG or WebP image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality). (default: 0.7)

imageWithRoundedCorner(blob, options)

Creates a new image by creating a copy of the given image with rounded corners.

Arguments

  • Image blobblob: Image to transform
  • Optionsdictionary: A dictionary specifying the options for the transformation
    • borderSizeint: The size of the border (default: 1)
    • cornerRadiusint: The radius of the corner edges (default: 0)
    • Android: format int: The output format: ImageFactory.JPEG, ImageFactory.PNG, ImageFactory.WEBP (default: ImageFactory.JPEG).
    • Android: qualityfloat: The quality of the resulting JPEG or WebP image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality). (default: 0.7).

imageAsThumbnail(blob, options)

Creates a new image by creating a copy of the given image that is squared to the thumbnail size.

Arguments

  • Image blobblob: Image to transform
  • Optionsdictionary: A dictionary specifying the options for the transformation
    • sizeint: The size of the thumbnail (default: 48)
    • borderSizeint: The size of the border (default: 1)
    • cornerRadiusint: The radius of the corner edges (default:0)
    • iOS: qualityint: The interpolation quality. One of the following constants (default: imagefactory.QUALITY_HIGH)
      • imagefactory.QUALITY_DEFAULT
      • imagefactory.QUALITY_NONE
      • imagefactory.QUALITY_LOW
      • imagefactory.QUALITY_MEDIUM
      • imagefactory.QUALITY_HIGH
    • Android: qualityfloat: The quality of the resulting JPEG or WebP image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality). (default: 0.7)
    • Android: ditherboolean: Indicates if dithering should be applied while scaling. (default: false)
    • Android: format int: The output format: ImageFactory.JPEG, ImageFactory.PNG, ImageFactory.WEBP (default: ImageFactory.JPEG)

imageAsResized(blob, options)

Creates a new image by creating a copy of the given image that is rescaled to the specified size.

Arguments

  • Image blobblob: Image to transform
  • Optionsdictionary: A dictionary specifying the options for the transformation
    • widthint: The width of the new image (default: image width)
    • heightint: The height of the new image (default: image height)
    • iOS: hiresboolean: Create a hires image (for Retina displays only)
    • iOS: qualityint: The interpolation quality. One of the following constants (default: imagefactory.QUALITY_HIGH)
      • imagefactory.QUALITY_DEFAULT
      • imagefactory.QUALITY_NONE
      • imagefactory.QUALITY_LOW
      • imagefactory.QUALITY_MEDIUM
      • imagefactory.QUALITY_HIGH
    • Android. format int: The output format of the image: either ImageFactory.PNG or ImageFactory.JPEG (default: ImageFactory.JPEG)
    • qualityfloat: The quality of the resulting JPEG or WebP image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality). (default: 0.7)

imageAsCropped(blob, options)

Creates a new image by creating a copy of the given image that is cropped to the specified bounds.

Arguments

  • Image blobblob: Image to transform
  • Optionsdictionary: A dictionary specifying the options for the transformation
    • widthint: The width of the new image (default: image width)
    • heightint: The height of the new image (default: image height)
    • xint: The x-coordinate of the upper-left corner of the bounds (default: image center - width / 2)
    • yint: The y-coordinate of the upper-left corner of the bounds (default: image center - height / 2)
    • Android: format int: The output format: ImageFactory.JPEG, ImageFactory.PNG, ImageFactory.WEBP (default: ImageFactory.JPEG)
    • Android: qualityfloat: The quality of the resulting JPEG or WebP image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality). (default: 0.7)

imageTransform(blob, options)

Creates a new image by applying a sequence of transformations to the image.

Arguments

  • Image blobblob: Image to transform
  • Transformdictionary: A sequence of transform specifications. Transforms are listed as additional parameters to the function and are applied in the order specified. Each transform is a dictionary with the options described above for each transform along with an additional 'type' property included with each dictionary of transform options.
    • typeint: The identifier of the transform to apply. One of the following constants
      • imagefactory.TRANSFORM_CROP
      • imagefactory.TRANSFORM_RESIZE
      • imagefactory.TRANSFORM_THUMBNAIL
      • imagefactory.TRANSFORM_ROUNDEDCORNER
      • imagefactory.TRANSFORM_TRANSPARENTBORDER
      • imagefactory.TRANSFORM_ALPHA
    • options as described in the above transforms

compress(blob, quality , format)

Creates a new image by creating a copy of the given image and applying the specified compression quality.

Arguments

  • Image blobblob: Image to compress
  • Compression Qualityfloat; The quality of the resulting JPEG or WebP image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality).
  • Android (optional): format int: The output format: ImageFactory.JPEG, ImageFactory.PNG, ImageFactory.WEBP (default: ImageFactory.JPEG)

compressToFile(blob, quality, fileUrl)

Compresses the given blob to an image file.

Arguments

  • Image blobblob: Image to write to file
  • Compression Qualityfloat; The quality of the resulting JPEG or WebP image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality).
  • fileUrl string: File path to write the image to. Supports extensions ".png", ".jpg", and ".jpeg". Android also supports ".webp".

Usage

See example.

License

Apache 2

Copyright

2011-present by Axway Appcelerator

6.1.0

3 years ago

6.0.0

4 years ago