public static function templateThumb($url, $template_id) { if ($url) { $base_url = UserUrl::template(true); return $base_url . '/' . 'thumbs' . '/' . $template_id; } else { $base_path = UserUrl::template(false); return UserUrl::createNonexistentDirInPath($base_path, 'thumbs') . DIRECTORY_SEPARATOR . $template_id; } }
public function actionViewSvg() { $this->layout = 'empty'; $id = Yii::$app->request->get('id', -1); $template = Template::findOne(['id' => $id]); if (!$template) { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Макет не найден')); $this->redirect(Url::toRoute(['templates/index'])); } $update_flag = false; $svg_path = UserUrl::templateThumb(false, $id) . '.svg'; $png_path = UserUrl::template(false) . DIRECTORY_SEPARATOR . 'thumbs'; if (!file_exists(UserUrl::templateThumb(false, $id) . '.svg')) { $update_flag = true; } else { $svg_update_time = filectime($svg_path); if ($template->updated_at > $svg_update_time) { $update_flag = true; } } // $update_flag=true; if ($update_flag) { $svg = str_replace('fill: transparent;', 'fill-opacity:0;', $template->svg); file_put_contents($svg_path, $svg); $batik_path = Yii::getAlias('@app') . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'batik' . DIRECTORY_SEPARATOR; // $cmds[]="java -d64 -Xms512m -Xmx4g -jar ".$batik_path."batik-rasterizer.jar -m image/jpg -w 350 -h 125 -q 0.99 -dpi 72 -d ".$png_path." ".$svg_path; exec("java -d64 -Xms512m -Xmx4g -jar " . $batik_path . "batik-rasterizer-1.8.jar -m image/jpg -w 350 -h 125 -q 0.65 -dpi 72 -d " . $png_path . " " . $svg_path); } $png = file_get_contents(UserUrl::templateThumb(false, $id) . '.jpg'); header('Content-type:image/png'); echo $png; }
public function actionSaveChanges() { $result = []; $this->layout = 'json'; $id = Yii::$app->request->get('id', 0); $json = Yii::$app->request->post('json', ''); $svg = Yii::$app->request->post('svg', ''); //$json_text= Yii::$app->request->post('json_text',''); //$svg_text= Yii::$app->request->post('svg_text',''); if (!empty($id)) { // $template=new Template(); $template = Template::findOne(['id' => $id]); $objects = json_decode($json, true); $ph = 0; $passepartout = true; $text_object = false; if ($json != '') { $objects = json_decode($json, true); foreach ($objects['objects'] as $key => $object) { if (!empty($object) && $object['type'] == 'placeholder') { if (isset($object['object_maybe_as_text']) && $object['object_maybe_as_text']) { $text_object = true; } $ph++; } } } $template->id = $id; $template->json = $json; $template->svg = $svg; //$template->json_text=$json_text; //$template->svg_text=$svg_text; $template->count_placeholder = $ph; $template->passepartout = $passepartout; $template->text_object = $text_object; if ($template->name == '') { $template->name = '#' . $id; } if ($template->update(false)) { $svg_path = UserUrl::templateThumb(false, $id) . '.svg'; $png_path = UserUrl::template(false) . DIRECTORY_SEPARATOR . 'thumbs'; $svg = str_replace('fill: transparent;', 'fill-opacity:0;', $template->svg); file_put_contents($svg_path, $svg); $batik_path = Yii::getAlias('@app') . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'batik' . DIRECTORY_SEPARATOR; // $cmds[]="java -d64 -Xms512m -Xmx4g -jar ".$batik_path."batik-rasterizer.jar -m image/jpg -w 350 -h 125 -q 0.99 -dpi 72 -d ".$png_path." ".$svg_path; Yii::getLogger()->log("java -d64 -Xms512m -Xmx4g -jar " . $batik_path . "batik-rasterizer-1.8.jar -m image/jpg -w 350 -h 125 -q 0.65 -dpi 72 -d " . $png_path . " " . $svg_path, YII_DEBUG); exec("java -d64 -Xms512m -Xmx4g -classpath " . $batik_path . DIRECTORY_SEPARATOR . "lib" . DIRECTORY_SEPARATOR . "batik-codec-1.8.jar" . " -jar " . $batik_path . "batik-rasterizer-1.8.jar -m image/jpg -w 350 -h 125 -q 0.65 -dpi 72 -d " . $png_path . " " . $svg_path); $updated_ago = Yii::t('app', 'Все изменения сохранены'); $result = ['response' => ['status' => true, 'changed_datetime' => date('d-m-Y H:i:s', $template->updated_at), 'updated_ago' => $updated_ago]]; } else { $result = ['error' => ['msg' => Yii::t('app', 'Не удалось сохранить'), 'json' => $json]]; } } else { $result = ['error' => ['msg' => Yii::t('app', 'Неверный id макета')]]; } return $this->render('json', ['result' => $result]); }