Skip to content

An easy to use iOS image cropping tool based on TOCropViewController.

License

Notifications You must be signed in to change notification settings

hansemannn/titanium-image-crop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Titanium Image Cropping Tool

An easy to crop images to different scales. Based on the awesome TOCropViewController library. Currently iOS only (!)

Example Screenshot

Example Screenshot rounded cropping

Requirements

  • Titanium SDK 9.2.0+ (this module is 100 % Swift based)

Methods

showCropDialog

Parameters

  • image (String, Ti.Blob, Ti.File)

  • croppingStyle 'circular' or 'default' (String) in not set 'default' is selected

  • aspectRatio (either a dictionary {x, y} of the ratio or one of the constants * below)

Constants

  • ASPECT_RATIO_SQUARE
  • ASPECT_RATIO_3x2
  • ASPECT_RATIO_5x3
  • ASPECT_RATIO_4x3
  • ASPECT_RATIO_5x4
  • ASPECT_RATIO_7x5
  • ASPECT_RATIO_16x9

Events

  • done
    • Attributes: image (Ti.Blob, if finished cropping), cancel (true if cancelled, false if completetd)
  • close

Notes

  • If opening the image crop dialog from a modal window, please set the modalStyle: Ti.UI.iOS.MODAL_PRESENTATION_OVER_CURRENT_FULL_SCREEN property (thanks to designbymind!)

Example

import ImageCrop from 'ti.imagecrop';

ImageCrop.addEventListener('done', event => {
  if (event.cancel) {
    return;
  }

  win.add(Ti.UI.createImageView({ height: 400, image: event.image }));
});

ImageCrop.addEventListener('close', event => {
  // Open other windows after the close has been triggered
  // to prevent transition glitches
});

const win = Ti.UI.createWindow({
  backgroundColor: '#fff'
});

const btn = Ti.UI.createButton({
  title: 'Show crop dialog'
});

btn.addEventListener('click', () => {
  ImageCrop.showCropDialog({
    image: 'test.jpg'
  });
});

win.add(btn);
win.open();

License

MIT

Author

Hans Knöchel