PHP code example of cozumel / yii2-image-cropper
1. Go to this page and download the library: Download cozumel/yii2-image-cropper library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cozumel / yii2-image-cropper example snippets
<?= \cozumel\cropper\ImageCropper::widget();
<?= \cozumel\cropper\ImageCropper::widget(['id' => 'user_profile_photo']);
$request = Yii::$app->request;
$x1 = $request->post('x1');
$x2 = $request->post('x2');
$y1 = $request->post('y1');
$y2 = $request->post('y2');
$h = $request->post('h');
$w = $request->post('w');
$image_height = $request->post('image_height');
$image_width = $request->post('image_width');
if (empty($w)) {
//nothing selected
return;
}
$image = imagecreatefromjpeg($image_source);
$width = imagesx($image);
$height = imagesy($image);
$resized_width = ((int) $x2) - ((int) $x1);
$resized_height = ((int) $y2) - ((int) $y1);
$resized_image = imagecreatetruecolor($resized_width, $resized_height);
imagecopyresampled($resized_image, $image, 0, 0, (int) $x1, (int) $y1, $width, $height, $width, $height);
imagejpeg($resized_image, $image_source);
php composer.phar
html
<img width="<?= $width;
html
$form = ActiveForm::begin(['action' => Yii::$app->urlManager->createUrl(['your/url/here']), 'options' => ['id' => 'crop_form'],
]);