protected function findModel($condition) { if (($model = Picture::findOne($condition)) !== null) { return $model; } else { $this->setHeader(400); echo json_encode(array('status' => 0, 'error_code' => 400, 'message' => 'Bad request'), JSON_PRETTY_PRINT); exit; } }
public function actionPong($id) { $picture = Picture::findOne(['id' => $id, 'state' => 'finishing']); if ($picture == null) { throw new HttpException(404, 'There are no memes here'); } /* @var \app\models\Picture $picture */ $path = \Yii::$app->basePath . '/web/ready/' . $picture->output; $img = imagecreatefrompng($path); #omg prosto omg unlink($path); imagejpeg($img, $path, 100); $picture->state = 'ready'; $picture->save(); \Yii::$app->mail->compose('result', ['picture' => $picture])->setFrom('*****@*****.**')->setTo($picture->email)->setSubject('Your DeepDream picture')->send(); echo 'ok'; }