public function testText() { if (!$this->isFontTestSupported()) { $this->markTestSkipped('Skipping ImageGdTest Gd not installed'); } $fontFile = Yii::getAlias('@yiiunit/data/imagine/GothamRnd-Light') . '.otf'; $img = Image::text($this->imageFile, 'Yii-2 Image', $fontFile, [0, 0], ['size' => 12, 'color' => '000']); $img->save($this->runtimeTextFile); $this->assertTrue(file_exists($this->runtimeTextFile)); }
public function actionRegistration() { $model = new ContactFormV3(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post()) && $model->validate()) { $newTicketName = Yii::$app->getSecurity()->generateRandomString('16'); $model->number = time(); Image::text(Yii::getAlias('@frontend/web/img/basic/ticket.jpg'), $model->name, Yii::getAlias('@frontend/web/doc/roboto.ttf'), [295, 345], ['color' => '000'])->save(Yii::getAlias('@frontend/web/tickets/' . $newTicketName . '.jpg'), ['quality' => 100]); Image::text(Yii::getAlias('@frontend/web/tickets/' . $newTicketName . '.jpg'), $model->email, Yii::getAlias('@frontend/web/doc/roboto.ttf'), [510, 396], ['color' => '000'])->save(Yii::getAlias('@frontend/web/tickets/' . $newTicketName . '.jpg'), ['quality' => 100]); Image::text(Yii::getAlias('@frontend/web/tickets/' . $newTicketName . '.jpg'), $model->number, Yii::getAlias('@frontend/web/doc/roboto.ttf'), [428, 33], ['color' => 'fff'])->save(Yii::getAlias('@frontend/web/tickets/' . $newTicketName . '.jpg'), ['quality' => 100]); Image::text(Yii::getAlias('@frontend/web/tickets/' . $newTicketName . '.jpg'), $model->number, Yii::getAlias('@frontend/web/doc/roboto.ttf'), [615, 795], ['color' => '000'])->save(Yii::getAlias('@frontend/web/tickets/' . $newTicketName . '.jpg'), ['quality' => 100]); Image::text(Yii::getAlias('@frontend/web/tickets/' . $newTicketName . '.jpg'), $model->phone, Yii::getAlias('@frontend/web/doc/roboto.ttf'), [295, 396], ['color' => '000'])->save(Yii::getAlias('@frontend/web/tickets/' . $newTicketName . '.jpg'), ['quality' => 100]); $model->ticket = $newTicketName . '.jpg'; if ($model->sendEmail(Yii::$app->params['supportEmail'])) { return 'success'; } else { return 'Что то пошло не так :( Попробуйте позднее'; } } return false; //throw new NotFoundHttpException('Page not found'); }
/** * After file save * Generate image thumb, if need. */ public function afterFileSave() { $images = ['original' => $this->_filePath]; // Thumbnail $thumb = $this->thumb; if (isset($thumb['generate']) && $thumb['generate']) { // Generate thumb image $images['thumbnail'] = $this->getThumbnailPath($images['original']); Image::thumbnail($images['original'], $thumb['width'], $thumb['height'])->save($images['thumbnail']); } // Add watermark to image $watermark = $this->watermark; if (isset($watermark['generate']) && $watermark['generate'] && !empty($watermark['content'])) { foreach ($images as $image) { if ($watermark['type'] == 'text') { Image::text($image, $watermark['content'], __DIR__ . '/simkai.ttf', [10, 10])->save($image); } elseif ($watermark == 'image' && is_file($watermark['content'])) { Image::watermark($image, $watermark['content']); } } } }