diff --git a/.htaccess b/.htaccess index a8a21a1..4434352 100644 --- a/.htaccess +++ b/.htaccess @@ -12,6 +12,7 @@ RewriteBase / # deal with admin first + RewriteRule ^storage/(.*)?$ /storage/$1 [L,PT] RewriteCond %{REQUEST_URI} ^/(admin) diff --git a/backend/components/ImageSizer.php b/backend/components/ImageSizer.php index 0880a9b..9aa9ff6 100644 --- a/backend/components/ImageSizer.php +++ b/backend/components/ImageSizer.php @@ -18,6 +18,7 @@ class ImageSizer extends Widget public $file; public $model; public $form; + public $multi = false; public function init(){ @@ -35,7 +36,8 @@ class ImageSizer extends Widget 'field' => $this->field, 'form' => $this->form, 'height' => $this->height, - 'width' => $this->width + 'width' => $this->width, + 'multi' => $this->multi ]); } diff --git a/backend/components/base/BaseController.php b/backend/components/base/BaseController.php index 21e496a..7141e09 100644 --- a/backend/components/base/BaseController.php +++ b/backend/components/base/BaseController.php @@ -26,49 +26,46 @@ class BaseController extends Controller { $img = Image::getImagine()->open(Yii::getAlias($imageAlias)); $size = $img->getSize(); - $ratio = $size->getWidth()/$size->getHeight(); - $height = $h; - $width = round($height * $ratio); + $width = $size->getWidth(); + $height = $size->getHeight(); + + if($width > $height) { + $y = 0; + $x = ($width - $height) / 2; + $smallestSide = $height; + } else { + $x = 0; + $y = ($height - $width) / 2; + $smallestSide = $width; + } + + + + +// die('$width = '.$width.','.'$height = '.$height.','.'$y = '.$y.','.'$x = '.$x.','.'$smallestSide = '.$smallestSide.',' ); +// +// $ratio = $size->getWidth()/$size->getHeight(); +// +// $height = $h; +// $width = round($height * $ratio); + + $image_p = imagecreatetruecolor($w, $h); + + $image = imagecreatefromjpeg($imageAlias); + imagecopyresampled($image_p, $image, 0, 0, $x, $y, + $w, $h, $smallestSide, $smallestSide); + + imagejpeg($image_p, $imageAliasSave); - $imagine = new Imagine(); - $imagine->open($imageAlias) - ->resize(new Box($width, $h)) - ->save($imageAlias, array('flatten' => false)); - Image::crop($imageAlias, $w, $h,[($width/2)-($w/2),0]) - ->save(Yii::getAlias($imageAliasSave), ['quality' => - 100]); } -// -// private function resizeImg($w, $h, $filepath,$newfilepath){ -// list($width, $height) = getimagesize($filepath); -// if($width > $height) { -// $y = 0; -// $x = ($width - $height) / 2; -// $smallestSide = $height; -// } else { -// $x = 0; -// $y = ($height - $width) / 2; -// $smallestSide = $width; -// } -// -// $image_p = imagecreatetruecolor($w, $h); -// -// $image = imagecreatefromjpeg($filepath); -// -// imagecopyresampled($image_p, $image, 0, 0, $x, $y, -// $w, $h, $smallestSide, $smallestSide); -// -// imagejpeg($image_p, $newfilepath); -// -// -// } + public function actionDownloadPhoto() { @@ -82,7 +79,7 @@ class BaseController extends Controller { $md5_file = md5_file($model->file->tempName); $imgDir = Yii::getAlias('@storage/'.$md5_file.'/'); $imageAlias = Yii::getAlias($imgDir.$model->width.'x'.$model->height.'.'.$model->file->extension); - $imageLink = '/storage/'.$md5_file.$model->width.'x'.$model->height.'.'.$model->file->extension; + $imageLink = '/storage/'.$md5_file.'/'.$model->width.'x'.$model->height.'.'.$model->file->extension; if(!is_dir($imgDir)) { mkdir($imgDir, 0755, true); diff --git a/backend/components/views/image_sizer.php b/backend/components/views/image_sizer.php index 8a824c2..6ff14ab 100644 --- a/backend/components/views/image_sizer.php +++ b/backend/components/views/image_sizer.php @@ -12,9 +12,11 @@ $this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl ?> -field( new \backend\models\ImageSizerForm(), 'file')->fileInput(['id'=>$field, 'data-url'=>"/admin/site/download-photo"]); ?> +field( new \backend\models\ImageSizerForm(), 'file')->fileInput(['id'=>$field, 'data-url'=>"/admin/site/download-photo", 'multiple'=> $multi?'multiple':'' ]); ?> field($model,$field)->hiddenInput(['id' => "{$field}_picture_link"]) ?> +field(new \backend\models\ImageSizerForm(),'height')->hiddenInput(['value' => $height])->label(false) ?> +field(new \backend\models\ImageSizerForm(), 'width')->hiddenInput(['value' => $width])->label(false) ?>
$field ? Html::img('/'.$model->$field): '' ?> @@ -25,14 +27,8 @@ $this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl $("#").fileupload({ dataType: 'json', - ImageSizerForm: { - height: , - width: - }, done: function (e, data) { var host = window.location.host.toString(); - console.log(host); - console.log(data.result.link); var img = ''; var block = $("#_img_block"); block.find('img').remove(); diff --git a/backend/models/Importers.php b/backend/models/Importers.php index 8dc3a35..d6f7d2d 100644 --- a/backend/models/Importers.php +++ b/backend/models/Importers.php @@ -36,6 +36,10 @@ class Importers extends BaseActiveRecord /** * @inheritdoc */ + public static function tableName() + { + return 'w_importers'; + } public function rules() { diff --git a/backend/views/user/_form.php b/backend/views/user/_form.php index 024795e..9a60b15 100644 --- a/backend/views/user/_form.php +++ b/backend/views/user/_form.php @@ -33,7 +33,7 @@ use yii\helpers\ArrayHelper; ], 'id', 'name')) ?> - $form, 'model'=> $model, 'field'=>'photo','width'=>200,'height'=>200]); ?> + $form, 'model'=> $model, 'field'=>'photo','width'=>200,'height'=>200,'multi'=>false]); ?> field($model, 'contacts')->textInput(['maxlength' => true]) ?> diff --git a/storage/.htaccess b/storage/.htaccess new file mode 100644 index 0000000..1b838f9 --- /dev/null +++ b/storage/.htaccess @@ -0,0 +1,7 @@ +RewriteEngine on +RewriteBase / +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d + +RewriteRule . index.php + diff --git a/storage/index.php b/storage/index.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/storage/index.php @@ -0,0 +1 @@ +