Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Jul 2, 2024
1 parent 4bb1087 commit dc98dea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions src/console/controllers/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use skeeks\imagine\Image;
use skeeks\cms\models\CmsStorageFile;
use yii\base\Exception;
use yii\db\Expression;
use yii\helpers\ArrayHelper;
use yii\helpers\Console;

/**
Expand Down Expand Up @@ -45,8 +47,15 @@ public function actionResizeOriginalImages($maxWidth = 1024, $maxHeight = 768)
->orderBy(['size' => SORT_DESC])
;



if ($total = $query->count()) {
$this->stdout("Неоптимизированных картинок: {$total} \n");
$sizeQuery = clone $query;
$sizeQuery->select(['sumsize' => new Expression('sum(size)')]);
$data = $sizeQuery->asArray()->one();
$formatedSumSize = \Yii::$app->formatter->asShortSize((float)ArrayHelper::getValue($data, 'sumsize'));

$this->stdout("Неоптимизированных картинок: {$total} шт. ({$formatedSumSize}) \n");
} else {
$this->stdout("Неоптимизированных картинок нет\n");
return;
Expand All @@ -63,16 +72,17 @@ public function actionResizeOriginalImages($maxWidth = 1024, $maxHeight = 768)
$fileRoot = $storageFile->getRootSrc();
$this->stdout("\tКартинка: {$storageFile->id}\n");
$this->stdout("\t\t{$fileRoot}\n");
$this->stdout("\t\t{$storageFile->image_width}x{$storageFile->image_height}\n");
$this->stdout("\t\tРазрешение: {$storageFile->image_width}x{$storageFile->image_height}\n");
$fileSize = filesize($fileRoot);
$this->stdout("\t\t{$fileSize}\n");
$fileSizeFormated = \Yii::$app->formatter->asShortSize($fileSize);
$this->stdout("\t\tРазмер: {$fileSizeFormated}\n");

$size = Image::getImagine()->open($fileRoot)->getSize();
$height = ($size->getHeight() * $maxWidth) / $size->getWidth();

$newHeight = (int)round($height);
$newWidth = $maxWidth;
$this->stdout("\t\tnew: {$newWidth}x{$newHeight}\n");
$this->stdout("\t\tНовое разрешение: {$newWidth}x{$newHeight}\n");

Image::thumbnail($fileRoot, $newWidth, $newHeight)->save($fileRoot);

Expand All @@ -84,7 +94,8 @@ public function actionResizeOriginalImages($maxWidth = 1024, $maxHeight = 768)

clearstatcache();
$fileSize = filesize($fileRoot);
$this->stdout("\t\tnew: {$fileSize}\n");
$fileSizeFormated = \Yii::$app->formatter->asShortSize($fileSize);
$this->stdout("\t\tНовый размер файла: {$fileSizeFormated}\n");

$storageFile->size = $fileSize;

Expand Down
1 change: 0 additions & 1 deletion src/controllers/AdminStorageFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ function(data)
],
'autoFilters' => [
'id',
''
],
'filtersModel' => [
'fields' => [
Expand Down
1 change: 1 addition & 0 deletions src/controllers/AdminUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,7 @@ public function addContractor()
//Создать компанию
$party = new PartyModel($dadata[0]);
$contractor = new CmsContractor();

$contractor->setAttributesFromDadata($party);
if (!$contractor->save()) {
throw new Exception("Не удалось создать компанию: ".print_r($contractor->errors, true));
Expand Down

0 comments on commit dc98dea

Please sign in to comment.