public function onBeforeWrite() { //Update individual focus points if ($this->owner->FocusXY) { $coords = FocusPointField::fieldValueToSourceCoords($this->owner->FocusXY); $this->owner->FocusX = $coords[0]; $this->owner->FocusY = $coords[1]; } parent::onBeforeWrite(); }
public function onBeforeWrite() { //Update individual focus points if ($this->owner->FocusXY) { $coords = FocusPointField::fieldValueToSourceCoords($this->owner->FocusXY); $this->owner->FocusX = $coords[0]; $this->owner->FocusY = $coords[1]; //Flush images if focus point has changed if ($this->owner->isChanged('FocusX') || $this->owner->isChanged('FocusY')) { $this->owner->deleteFormattedImages(); } } parent::onBeforeWrite(); }
public function __construct(Image $image) { // call FocusPointField parent::__construct($image); // Cropper Requirements::css(FOCUSPOINTCROP_DIR . '/bower_components/cropper/dist/cropper.css'); Requirements::javascript(FOCUSPOINTCROP_DIR . '/bower_components/cropper/dist/cropper.js'); Requirements::css(FOCUSPOINTCROP_DIR . '/css/CropperField.css'); Requirements::javascript(FOCUSPOINTCROP_DIR . '/javascript/CropperField.js'); // Add CropData field // $this->setOptions(array()); // sets default options $this->push($field = TextField::create('CropData')); // Update field title & provide instructions $this->setTitle(_t('FC_Crop.FieldTitle', 'Crop & Focus Point')); $this->push(LiteralField::create('CropDescr', '<p class="cropper_instruction">' . _t('FC_Crop.Descr', 'Drag & resize the Cropping Area (blue rectangle) and click to select the Focus Point (main subject) of the image to ensure it is not lost during cropping') . '</p>')); // feed config to js $field->setAttribute('data-cropconfig', json_encode($this->config()->cropconfig)); // feed some more info to js $sizes = array('originalWidth' => $image->width, 'originalHeight' => $image->height, 'previewWidth' => $image->FocusPointFieldImage()->width, 'previewHeight' => $image->FocusPointFieldImage()->height); $field->setAttribute('data-cropsizing', json_encode($sizes)); }
public function getFileEditFields(File $file) { $fields = new FieldList(); if ($this->getUseCropbox()) { $f = new CropboxField($name = "Cropbox", $title = "Crop box", $imageID = $file->ID); $f->addExtraClass('stacked'); $fields->push($f); } if ($this->getUseFocuspoint()) { $f = new FocusPointField($name = "FocusXY", $title = "Focus point", $imageID = $file->ID); $f->setValue(FocusPointField::sourceCoordsToFieldValue($file->FocusX, $file->FocusY)); $f->addExtraClass('stacked'); $fields->push($f); } return $fields; }