Skip to content

haunt-digital/image-cropper

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CitaNZ's Image Cropper

It's a continious development of Salted Herring's Cropper Field for SilverStripe - 4 (https://github.com/salted-herring/salted-cropper)

Usage

  1. Install
composer require cita/image-cropper
  1. /dev/build?flush=all

  2. Sample code:

    ...
    use Cita\ImageCropper\Model\CitaCroppableImage;
    use Cita\ImageCropper\Fields\CroppableImageField;
    ...
    private static $has_one = array(
        'Photo'     =>  CitaCroppableImage::class
    );
    
    
    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        ...
        // adding a free cropper
        $fields->addFieldToTab(TAB_NAME, CroppableImageField::create('PhotoID', A_TITLE_TO_THE_FILED));
    
        // adding cropper with ratio
        $fields->addFieldToTab(TAB_NAME, CroppableImageField::create('PhotoID', A_TITLE_TO_THE_FILED)->setCropperRatio(16/9));
        ...
        return $fields;        
    }
  3. Add image > upload/select > save > edit > do your cropping > save

  4. Output

    $Photo
    $Photo.Cropped
    $Photo.Cropped.SetWidth(100)

AWS support

If you are using SS's S3 assets module to store your images, you may also want to add this into your site's config yaml

SilverStripe\Admin\LeftAndMain:
  extra_requirements_javascript:
    - 'resources/vendor/cita/image-cropper/client/js/s3-workaround.js'

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 63.2%
  • JavaScript 32.6%
  • Scheme 3.5%
  • CSS 0.7%