test.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. use demi\cropper\Cropper;
  3. use yii\web\JsExpression;
  4. echo "<img id='myImage' src='' width='100px'/>";
  5. $image = '/topics/36_size2.jpg';
  6. echo Cropper::widget([
  7. // If true - it's output button for toggle modal crop window
  8. 'modal' => true,
  9. // You can customize modal window. Copy /vendor/demi/cropper/views/modal.php
  10. 'modalView' => '@vendor/demi/cropper/views/modal.php',
  11. // URL-address for the crop-handling request
  12. // By default, sent the following post-params: x, y, width, height, rotate
  13. 'cropUrl' => ['cropImage', 'id' => $image],
  14. // Url-path to original image for cropping
  15. 'image' => Yii::$app->request->baseUrl . '/images/' . $image,
  16. // The aspect ratio for the area of cropping
  17. 'aspectRatio' => 4 / 3, // or 16/9(wide) or 1/1(square) or any other ratio. Null - free ratio
  18. // Additional params for JS cropper plugin
  19. 'pluginOptions' => [
  20. // All possible options: https://github.com/fengyuanchen/cropper/blob/master/README.md#options
  21. 'minCropBoxWidth' => 400, // minimal crop area width
  22. 'minCropBoxHeight' => 300, // minimal crop area height
  23. ],
  24. // HTML-options for widget container
  25. 'options' => [],
  26. // HTML-options for cropper image tag
  27. 'imageOptions' => [],
  28. // Translated messages
  29. 'messages' => [
  30. 'cropBtn' => Yii::t('app', 'Crop'),
  31. 'cropModalTitle' => Yii::t('app', 'Select crop area and click "Crop" button'),
  32. 'closeModalBtn' => Yii::t('app', 'Close'),
  33. 'cropModalBtn' => Yii::t('app', 'Crop selected'),
  34. ],
  35. // Additional ajax-options for send crop-request. See jQuery $.ajax() options
  36. 'ajaxOptions' => [
  37. 'success' => new JsExpression(<<<JS
  38. function(data) {
  39. // data - your JSON response from [[cropUrl]]
  40. $("#myImage").attr("src", data.croppedImageSrc);
  41. }
  42. JS
  43. ),
  44. ],
  45. ]);
  46. ?>
  47. test