Exemplo n.º 1
0
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>



                                                    </div>

                                                    <?php 
    } else {
        ?>

                                                        <div style="width: 100%; height: 100%; position: absolute;   background-size: cover; background-image: url('<?php 
        echo UserUrl::stylePaddedPassepartout(true, $style->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($style->padded_passepartout_key, UserUrl::IMAGE_ORIGINAL);
        ?>
');">

                                                            <div class="svg svg-<?php 
        echo $key;
        ?>
"  data-index="<?php 
        echo $key;
        ?>
" style=" height: 100%;">
                                                                <svg  height="100%" viewBox="0 0 700 250">
                                                                    <?php 
        if (!empty($page['svg'])) {
            echo $page['svg'];
        }
Exemplo n.º 2
0
    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);
        }
    }
Exemplo n.º 3
0
 public function updatePaddedPassepartout()
 {
     //Удаляем старую подложку паспарту
     foreach (UserUrl::$IMAGE_SIZE as $image_size => $value) {
         $file_path = UserUrl::stylePaddedPassepartout(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($this->padded_passepartout_key, $image_size);
         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::stylePaddedPassepartout(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_ORIGINAL);
             $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::stylePaddedPassepartout(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, $image_size);
                 $image->resize($param['width'], $param['height'], $type);
                 $image->save($file_resize_path);
             }
             $this->padded_passepartout_key = $file_id;
             if (!$this->save()) {
                 return ['error' => ['msg' => Yii::t('app', 'Ошибка записи в базу-данных')]];
             } else {
                 return ['response' => ['status' => true, 'padded_passepartout_key' => $file_id, 'padded_passepartout_thumb_url' => UserUrl::stylePaddedPassepartout(true, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_THUMB)]];
             }
         } else {
             return ['error' => ['msg' => Yii::t('app', 'Данные не получены')]];
         }
     } else {
         return ['error' => ['msg' => Yii::t('app', 'Данные не получены')]];
     }
 }
Exemplo n.º 4
0
 public function addNewPage($page_index, $photo_id)
 {
     $style = Style::findOne(['id' => $this->style_id, 'delete' => 0]);
     $mapTemplates = $this->getMapTemplates();
     $pages = [['photos' => [['file_key' => $photo_id, 'pos_dx' => 0, 'pos_dy' => 0, 'scale' => 1]]]];
     foreach ($pages as $key => $page) {
         $pages[$key]['svg'] = $this->renderSvgPage($pages[$key], $mapTemplates, $style);
         $pages[$key]['svg_thumb'] = $this->renderSvgPage($pages[$key], $mapTemplates, $style, UserUrl::IMAGE_SMALL);
         $pages[$key]['json'] = $this->renderJsonPage($pages[$key], $mapTemplates, $style);
         $pages[$key]['action'] = 'print';
         $pages[$key]['flyleaf'] = false;
     }
     Utils::array_insert($this->data['pages'], $pages[0], intval($page_index));
     if ($this->save()) {
         $backgroundUrl = UserUrl::stylePaddedPassepartout(true, $style->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($style->padded_passepartout_key, UserUrl::IMAGE_ORIGINAL);
         return ['response' => ['status' => true, 'page_index' => $page_index, 'pages' => Utils::pages_filter($this->data['pages']), 'background_url' => $backgroundUrl]];
     } else {
         return ['error' => ['msg' => Yii::t('app', 'Не удалось записать в базу-данных')]];
     }
 }