</div> </div> </div> </div> <div class="bb-item" id="sitem2"> <div class="content" > <div class="box " style=" "> <div id="coverPaddedBackground" style="width: 100%; height: 100%; position: absolute; border-radius: 3px; background-size: cover; background-image: url('<?php echo UserUrl::coverPadded(true, $selected_cover->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($selected_cover->padded_cover, UserUrl::IMAGE_ORIGINAL, 'png'); ?> ');"> <div class="bb-custom-wrapper"> <div id="bb-bookblock" class="bb-bookblock"> <?php foreach ($pages as $key => $page) { ?> <div class="bb-item bb-pitem" id="item<?php
public function actionPageSvgThumb() { // $pid = pcntl_fork(); $settingForm = new SettingForm(); $photobook_thumb_as_object = $settingForm->getValue('photobook_thumb_as_object', false); if ($photobook_thumb_as_object) { header('Content-type: image/svg+xml'); } $ref = Yii::$app->request->get('ref'); $id = Yii::$app->request->get('id'); $page_index = Yii::$app->request->get('page'); $this->layout = 'empty'; if (!empty($ref) && !empty($id)) { $user_id = AlphaId::id($ref, true); $pb_id = AlphaId::id($id, true); $model = new PhotobookForm(); if ($model->loadById($pb_id)) { $styleForm = new StyleForm(); $style_background_image_base64 = ''; if ($styleForm->loadById($model->style_id)) { $padded_padded_passepartout_path = UserUrl::stylePaddedPassepartout(false, $styleForm->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($styleForm->padded_passepartout_key, UserUrl::IMAGE_THUMB); $padded_padded_passepartout_data = file_get_contents($padded_padded_passepartout_path); $type = 'jpg'; $style_background_image_base64 = 'data:image/' . $type . ';base64,' . base64_encode($padded_padded_passepartout_data); } $coverForm = new CoverForm(); $coverForm->loadById($model->cover_id); $padded_cover_image_path = UserUrl::coverPadded(false, $coverForm->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($coverForm->padded_cover, UserUrl::IMAGE_THUMB, 'png'); $padded_cover_data = file_get_contents($padded_cover_image_path); $type = 'png'; $padded_cover_base64 = 'data:image/' . $type . ';base64,' . base64_encode($padded_cover_data); if (!empty($model->data['pages'][$page_index])) { $page = $model->data['pages'][$page_index]; $svg = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" x="0" y="0" width="710" height="260" preserveAspectRatio="none" overflow="visible" xml:space="preserve" viewBox="0 0 710 260"> <svg width="100%" height="100%" x="0" y="0" viewBox="0 0 710 260" > <image xlink:href="' . $padded_cover_base64 . '" x="0" y="0" height="260px" width="710px"/> <image xlink:href="' . $style_background_image_base64 . '" x="5" y="5" height="250px" width="700px"/> </svg> <svg width="700" height="250" x="5" y="5" viewBox="0 0 700 250"> ' . str_replace('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">', '', str_replace('<' . '?xml version="1.0" encoding="UTF-8" standalone="no"?' . '>', '', $page['svg_thumb'])) . ' </svg> </svg>'; if ($photobook_thumb_as_object) { echo $svg; } else { $file_id = md5($svg); $thumb_path = UserUrl::photobookPageThumb(false, $model->id, $model->user_id); //UserUrl::imageFile($file_id, UserUrl::IMAGE_THUMB); $thumb_path_file = $thumb_path . DIRECTORY_SEPARATOR . $file_id . '.jpg'; $svg_path_file = $thumb_path . DIRECTORY_SEPARATOR . $file_id . '.svg'; $headers = Yii::$app->response->headers; if (file_exists($thumb_path_file)) { $headers->add('Content-type', 'image/jpeg'); $headers->add('Cache-Control', "max-age=" . 60 * 60 * 24); $values = $headers->remove('Pragma'); // Yii::$app->response->headers=$values; $content = file_get_contents($thumb_path_file); Yii::$app->response->content = $content; //Yii::$app->response-> Yii::$app->response->send(); } else { $svg = str_replace('fill: transparent;', 'fill-opacity:0;', $svg); $svg = str_replace('fill="transparent"', 'style="fill-opacity:0;"', $svg); $svg = str_replace('<rect/>', '', $svg); file_put_contents($svg_path_file, $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('batik:' . "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 " . $thumb_path . " " . $svg_path_file, YII_DEBUG); 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 " . $thumb_path . " " . $svg_path_file); $headers->add('Content-type', 'image/jpeg'); $headers->add('Cache-Control', "max-age=" . 60 * 60 * 24); $values = $headers->remove('Pragma'); //Yii::$app->response->headers=$values; $content = file_get_contents($thumb_path_file); Yii::$app->response->content = $content; Yii::$app->response->send(); } } } else { //throw new \yii\web\HttpException(404, 'Not found', 404); } } else { //throw new \yii\web\HttpException(404, 'Not found', 404); } } else { //throw new \yii\web\HttpException(404, 'Not found', 404); } }
?> </div> <input type="file" class="fileupload-padded-cover" name="CoverForm[photo]" value="" data-url="<?php echo Url::toRoute(['covers-api/upload-padded-cover', 'id' => $cover->id]); ?> "> </span> </form> <div id="paddedCoverPreview"> <?php if (file_exists(UserUrl::coverPadded(false, $cover->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($cover->padded_cover, UserUrl::IMAGE_THUMB, 'png'))) { ?> <div class="row"><div class="col-lg-3"><div class="thumbnail"><a class="thumbnail"><img src="<?php echo UserUrl::coverPadded(true, $cover->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($cover->padded_cover, UserUrl::IMAGE_THUMB, 'png'); ?> " /></a></div></div></div> <?php } ?> </div> </div> <div class="form-group"> <form action="<?php echo Url::toRoute(['covers-api/upload-cover-front', 'id' => $cover->id]); ?>
public function updatePaddedCover() { //Удаляем старую подложку обложки foreach (UserUrl::$IMAGE_SIZE as $image_size => $value) { $file_path = UserUrl::coverPadded(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($this->padded_cover, $image_size, 'png'); if (file_exists($file_path)) { unlink($file_path); } } $file = UploadedFile::getInstance($this, 'photo'); if ($file) { if ($file->size !== 0) { $file_id = AlphaId::id(rand(10000000000, 9999999999999)); $file_path = UserUrl::coverPadded(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_ORIGINAL, 'png'); $file->saveAs($file_path); foreach (UserUrl::$IMAGE_SIZE as $image_size => $param) { if ($image_size == UserUrl::IMAGE_ORIGINAL) { continue; } $image = Yii::$app->image->load($file_path); $type = Yii\image\drivers\Image::WIDTH; $file_resize_path = UserUrl::coverPadded(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, $image_size, 'png'); $image->resize($param['width'], $param['height'], $type); $image->save($file_resize_path); } $this->padded_cover = $file_id; if (!$this->save()) { return ['error' => ['msg' => Yii::t('app', 'Ошибка записи в базу-данных')]]; } else { return ['response' => ['status' => true, 'padded_cover' => $file_id, 'padded_cover_thumb_url' => UserUrl::coverPadded(true, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_THUMB, 'png')]]; } } else { return ['error' => ['msg' => Yii::t('app', 'Данные не получены')]]; } } else { return ['error' => ['msg' => Yii::t('app', 'Данные не получены')]]; } }