Skip to content

Commit

Permalink
Merge pull request #30 from linuskohl/master
Browse files Browse the repository at this point in the history
Add aspectRatio setting
  • Loading branch information
krivochenko committed Nov 15, 2017
2 parents a966bf1 + 434c6d4 commit 14b3639
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Widget has following properties:
| maxSize | The maximum file size (kb). | 2097152 |No |
| cropAreaWidth | Width box for preview | 300 |No |
| cropAreaHeight | Height box for preview | 300 |No |
| aspectRatio | Fix aspect ratio of cropping area | null |No |
| extensions | Allowed file extensions (string). | jpeg, jpg, png, gif |No |


Expand Down Expand Up @@ -107,4 +108,4 @@ This picture is displayed in the widget and users have the ability to crop it or

When the user clicks "Crop image", a request with file and coordinates is sent to the server. This picture is displayed in the form, and user can save it, or change crop area, or upload another photo.

![0ejh55q](https://cloud.githubusercontent.com/assets/7313306/7107359/bddeae36-e16b-11e4-889b-484d7dbad8a5.png)
![0ejh55q](https://cloud.githubusercontent.com/assets/7313306/7107359/bddeae36-e16b-11e4-889b-484d7dbad8a5.png)
7 changes: 6 additions & 1 deletion Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Widget extends InputWidget
public $extensions = 'jpeg, jpg, png, gif';
public $onCompleteJcrop;
public $pluginOptions = [];
public $aspectRatio = null;

/**
* @inheritdoc
Expand Down Expand Up @@ -76,9 +77,13 @@ public function registerClientAssets()
'allowedExtensions' => explode(', ', $this->extensions),
'size_error_text' => Yii::t('cropper', 'TOO_BIG_ERROR', ['size' => $this->maxSize / (1024 * 1024)]),
'ext_error_text' => Yii::t('cropper', 'EXTENSION_ERROR', ['formats' => $this->extensions]),
'accept' => 'image/*'
'accept' => 'image/*',
], $this->pluginOptions);

if(is_numeric($this->aspectRatio)) {
$settings['aspectRatio'] = $this->aspectRatio;
}

if ($this->onCompleteJcrop)
$settings['onCompleteJcrop'] = $this->onCompleteJcrop;

Expand Down
2 changes: 1 addition & 1 deletion messages/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

return [
'sourcePath' => __DIR__ . DIRECTORY_SEPARATOR . '..',
'languages' => ['ru', 'en', 'uk', 'pl'],
'languages' => ['ru', 'en', 'uk', 'pl', 'de'],
'translator' => 'Yii::t',
'sort' => false,
'removeUnused' => false,
Expand Down
29 changes: 29 additions & 0 deletions messages/de/cropper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Message translations.
*
* This file is automatically generated by 'yii message' command.
* It contains the localizable messages extracted from source code.
* You may modify this file by translating the extracted messages.
*
* Each array element represents the translation (value) of a message (key).
* If the value is empty, the message is considered as not translated.
* Messages that no longer need translation will have their translations
* enclosed between a pair of '@@' marks.
*
* Message string can be used with plural forms format. Check i18n section
* of the guide for details.
*
* NOTE: this file must be saved in UTF-8 encoding.
*/
return [
'DEFAULT_LABEL' => 'Bild Datei hier hineinziehen oder clicken und auswählen',
'CROP_PHOTO' => 'Bild zuschneiden',
'DELETE_PHOTO' => 'Bild löschen',
'ERROR_CAN_NOT_UPLOAD_FILE' => 'Datei kann nicht hochgeladen werden',
'MISSING_ATTRIBUTE' => 'Attibut "{attribute}" muss spezifiziert sein',
'ONLY_POST_REQUEST' => 'Nur POST-Anfragen erlaubt',
'UPLOAD_ANOTHER_PHOTO' => 'Anderes Bild hochladen',
'TOO_BIG_ERROR' => 'Datei überschreitet die erlaubte Größe von ({size} Mb)',
'EXTENSION_ERROR' => 'Lediglich die folgenden Formate sind zulässig: {formats}'
];
6 changes: 3 additions & 3 deletions messages/en/cropper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* NOTE: this file must be saved in UTF-8 encoding.
*/
return [
'DEFAULT_LABEL' => 'For download the new photos, click here or drag a file here',
'CROP_PHOTO' => 'Crop photo',
'DELETE_PHOTO' => 'Delete photo',
'DEFAULT_LABEL' => 'Click and select or drag an image file here',
'CROP_PHOTO' => 'Crop image',
'DELETE_PHOTO' => 'Delete image',
'ERROR_CAN_NOT_UPLOAD_FILE' => 'Can`t upload file',
'MISSING_ATTRIBUTE' => 'Attibute "{attribute}" must be specified',
'ONLY_POST_REQUEST' => 'Allowed only POST-request',
Expand Down

0 comments on commit 14b3639

Please sign in to comment.