Skip to content

The CropField module provides `CropField`, a Picture Upload in Frontend with integratet JCrop functionallity, based on Dropzone.

License

Notifications You must be signed in to change notification settings

hex0id/silverstripe-cropfield

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cropfield for SilverStripe

PictureUpload with Jcrop.

Introduction

The CropField module provides CropField, a Picture Upload in Frontend with integratet JCrop functionallity, based on Dropzone.

Features

  • Upload Images on the frontend, and directly Crop the with JCrop
  • Drag-and-drop uploading

Requirements

Usage

	function ImageFrom(){
		$fields = new FieldList(
			$cf = new CropField("Image", "Image")
		);
		$actions = new FieldList(
			new FormAction("submit", "submit")
		);
		return new Form($this, "ImageFrom", $fields, $actions);
	}
	
	function submit($data,$form){
		$original = Image::get()->byID($data['Image']['ID']);
		$cropped = $original->CroppedFromPos($data['Image']['width'], $data['Image']['height'], $data['Image']['posX'], $data['Image']['posY']);
		//overwrite the Original Image by the Cropped one
		copy(Director::baseFolder() . "/" . $cropped->Filename, Director::baseFolder() . "/" . $original->Filename);
		$this->data()->ImageID = $original->ID;
		$this->data()->write();
		$this->redirectBack();
	}

More advanced options

CropField::create('Image', 'Upload an image')
	->setBoxWidth(600) //set BoxWidth to 0 to use full Form width
	->setBoxHeight(600)
	->setMaxWidth(0)
	->setMaxHeight(0)
	->setMaxWidth(0)
	->setMaxHeight(0)
	->setAspectRatio(1)
  ));

About

The CropField module provides `CropField`, a Picture Upload in Frontend with integratet JCrop functionallity, based on Dropzone.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 83.2%
  • PHP 7.6%
  • CSS 4.7%
  • Scheme 4.5%