/** * Ruturn institute-setup page if application is no-institute found. * @return mixed */ public function actionInstituteSetup() { $chkInstituteTbl = \app\models\Organization::find()->exists(); if ($chkInstituteTbl) { return $this->redirect(['user-setup']); } $model = new \app\models\Organization(); $model->scenario = 'insert'; if (isset($_POST['Organization']) && $model->load(Yii::$app->request->post())) { $image_string = null; $model->attributes = $_POST['Organization']; $model->org_email = strtolower($_POST['Organization']['org_email']); $model->created_at = new \yii\db\Expression('NOW()'); ob_start(); if (!empty($_FILES['Organization']['tmp_name']['org_logo'])) { $file = UploadedFile::getInstance($model, 'org_logo'); $model->org_logo_type = $file->type; $fp = fopen($file->tempName, 'r'); $content = fread($fp, filesize($file->tempName)); fclose($fp); if ($model->org_logo_type == "image/png") { $src_img = imagecreatefrompng($file->tempName); $dst_img = imagecreatetruecolor(90, 70); imagealphablending($dst_img, false); imagesavealpha($dst_img, true); $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127); imagefilledrectangle($dst_img, 0, 0, 90, 70, $transparent); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, 90, 70, imagesx($src_img), imagesy($src_img)); imagepng($dst_img); ob_start(); imagepng($dst_img); $image_string = ob_get_contents(); ob_end_flush(); } if ($model->org_logo_type == "image/jpg" || $model->org_logo_type == "image/jpeg") { $src_img = imagecreatefromjpeg($file->tempName); $dst_img = imagecreatetruecolor(90, 70); imagealphablending($dst_img, false); imagesavealpha($dst_img, true); $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127); imagefilledrectangle($dst_img, 0, 0, 90, 70, $transparent); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, 90, 70, imagesx($src_img), imagesy($src_img)); imagejpeg($dst_img); ob_start(); imagepng($dst_img); $image_string = ob_get_contents(); ob_end_flush(); } if ($model->org_logo_type == "image/gif") { $src_img = imagecreatefromgif($file->tempName); $dst_img = imagecreatetruecolor(90, 70); imagealphablending($dst_img, false); imagesavealpha($dst_img, true); $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127); imagefilledrectangle($dst_img, 0, 0, 90, 70, $transparent); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, 90, 70, imagesx($src_img), imagesy($src_img)); imagepng($dst_img); ob_start(); imagecreatefromgif($dst_img); $image_string = ob_get_contents(); ob_end_flush(); } $model->org_logo = $image_string; } if ($model->save()) { return $this->redirect(['user-setup']); } } return $this->render('institute-setup', ['model' => $model]); }