public function run()
    {
        $image_posX = 0;
        $image_posY = 0;
        $place_width = 700;
        $place_height = 350;
        $img_path = UserUrl::styleBackground(false, $this->style_id) . '/' . UserUrl::imageFile($this->file_key, $this->image_size);
        $size = getimagesize($img_path);
        $image_real_width = $size[0];
        $image_real_height = $size[1];
        $thumb_width = $place_width;
        $thumb_height = $place_height;
        $width = $image_real_width;
        $height = $image_real_height;
        $original_aspect = $width / $height;
        $thumb_aspect = $thumb_width / $thumb_height;
        if ($original_aspect >= $thumb_aspect) {
            // If image is wider than thumbnail (in aspect ratio sense)
            $new_height = $thumb_height;
            $new_width = $width / ($height / $thumb_height);
        } else {
            // If the thumbnail is wider than the image
            $new_width = $thumb_width;
            $new_height = $height / ($width / $thumb_width);
        }
        $image_posX = 0 - ($new_width - $thumb_width) / 2;
        $image_posY = 0 - ($new_height - $thumb_height) / 2;
        $image_real_width = $new_width;
        $image_real_height = $new_height;
        $img_url = UserUrl::styleBackground(true, $this->style_id) . '/' . UserUrl::imageFile($this->file_key, $this->image_size);
        $uid = rand(1, 99999999999999999);
        $content = '<g xmlns:xlink="http://www.w3.org/1999/xlink"  class="placeholder"  transform="translate(0, 0)" width="{width}" height="{height}" clip-path="url(#clip-path-{uid})" >
                    <defs>
                        <clipPath id="clip-path-{uid}">
                            <path d="M 0 0 h {width}  v {height}  h -{width}  v -{height}  z"/>
                        </clipPath>
                    </defs>

                    <path fill="#999999" fill-opacity="1" clip-path="url(#clip-path-{uid})" d="M 0 0 h {width}  v {height}  h -{width}  v -{height}  z"/>

                    <g >
                        <g transform="translate({img_pos_x},{img_pos_y})" width="{width}" height="{height}" pointer-events="none">
                            <image width="{image_real_width}" height="{image_real_height}" xlink:href="{img_url}"/>
                        </g>
                    </g>

                </g>';
        //xlink
        echo Yii::t('app', $content, ['width' => $place_width, 'height' => $place_height, 'uid' => $uid, 'image_real_width' => $image_real_width, 'image_real_height' => $image_real_height, 'img_url' => $img_url, 'w2' => $place_width / 2, 'h2' => $place_height / 2, 'img_pos_x' => $image_posX, 'img_pos_y' => $image_posY]);
    }
 public function run()
 {
     $style_css = '';
     $background_image = '';
     if (!empty($this->background_image)) {
         $background_image = UserUrl::styleBackground(true, $this->style_id) . '/' . UserUrl::imageFile($this->background_image, UserUrl::IMAGE_THUMB);
     }
     $style_css = 'background-color: ' . $this->background_color . ';';
     if (!empty($background_image)) {
         $style_css .= 'background-image:url(' . $background_image . '); background-size:cover;  background-repeat: no-repeat;';
     }
     $img = Html::img(Url::toRoute(['templates/view-svg', 'id' => $this->template_id]), ['style' => $style_css]);
     $a = Html::a($img, Url::toRoute(['templates/view-svg', 'id' => $this->template_id]), ['class' => 'thumb thumb-template thumb-template-' . $this->count, 'data-id' => $this->count, 'data-templateid' => $this->template_id, 'data-index' => $this->group_index]);
     echo $a;
 }
Beispiel #3
0
 public function changeGroupBackgroundColor($group_index, $color)
 {
     if (!isset($this->data['layouts'][$group_index])) {
         $result = ['error' => ['msg' => Yii::t('app', 'Группа не найдена {param}', ['param' => $group_index])]];
     } else {
         $this->data['layouts'][$group_index]['background_color'] = $color;
         $group = $this->data['layouts'][$group_index];
         //Если есть старый фон удаляем его
         if (!empty($group['background_image'])) {
             $file_id = $group['background_image'];
             $file_path = UserUrl::styleBackground(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_ORIGINAL);
             if (file_exists($file_path)) {
                 unlink($file_path);
             }
             foreach (UserUrl::$IMAGE_SIZE as $key => $size) {
                 if ($key != UserUrl::IMAGE_ORIGINAL) {
                     $file_resize_path = UserUrl::styleBackground(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, $key);
                     if (file_exists($file_resize_path)) {
                         unlink($file_resize_path);
                     }
                 }
             }
         }
         $this->data['layouts'][$group_index]['background_image'] = '';
         if ($this->save()) {
             $result = ['response' => ['status' => true, 'background_color' => $color]];
         } else {
             $result = ['error' => ['msg' => Yii::t('app', 'Не удалось сохранить изменения')]];
         }
     }
     return $result;
 }
Beispiel #4
0
?>
                                </div>
                                <input type="file" class="fileupload-cover-back" name="CoverForm[photo]" value="" data-url="<?php 
echo Url::toRoute(['covers-api/upload-cover-back', 'id' => $cover->id]);
?>
">
                            </span>
                    </form>

                    <div id="coverBackPreview">

                        <?php 
if (file_exists(UserUrl::coverBack(false, $cover->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($cover->cover_back, UserUrl::IMAGE_THUMB, 'png'))) {
    ?>
                            <div class="row"><div class="col-lg-3"><div class="thumbnail"><a class="thumbnail"><img src="<?php 
    echo UserUrl::coverBack(true, $cover->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($cover->cover_back, UserUrl::IMAGE_THUMB, 'png');
    ?>
" /></a></div></div></div>
                        <?php 
}
?>
                    </div>
                </div>


                <div class="row">
                    <div class="col-md-6">

                        <div class="form-group">

                            <div class="input-group">
Beispiel #5
0
 public static function logoUrl($image_id, $image_size = UserUrl::IMAGE_ORIGINAL, $ext = 'jpg', $user_id = null)
 {
     if (Yii::$app->user->isGuest && $user_id == null) {
         return Yii::getAlias('@web') . '/images/default-logo.png';
     }
     if ($user_id == null) {
         $user_id = Yii::$app->user->identity->getId();
     }
     if ($image_id !== 'default-logo') {
         $alpha_id = AlphaId::id($user_id);
         return Yii::getAlias('@web') . '/uploads/' . $alpha_id . '/logo/' . UserUrl::imageFile($image_id, $image_size, $ext);
     } else {
         return Yii::getAlias('@web') . '/images/default-logo.png';
     }
 }
    public function run()
    {
        $image_posX = 0;
        $image_posY = 0;
        /* $scale=2;
           $image_real_width=$this->place_width*$scale;
           $image_real_height=$this->place_height*$scale;*/
        $img_path = UserUrl::photobookTexts(false, $this->photobook_id, $this->user_id) . '/' . UserUrl::imageFile($this->photo_id, $this->image_size, 'png');
        $img_url = UserUrl::photobookTexts(true, $this->photobook_id, $this->user_id) . '/' . UserUrl::imageFile($this->photo_id, $this->image_size, 'png');
        $img_path = UserUrl::photobookTexts(false, $this->photobook_id, $this->user_id) . '/' . UserUrl::imageFile($this->photo_id, $this->image_size, 'png');
        if (!file_exists($img_path) || $this->update_img) {
            $place_width = $this->place_width;
            $place_height = $this->place_height;
            /* $resize_val=UserUrl::$IMAGE_SIZE[$this->image_size]['size'];
                           $w=Utils::pxToMm(Utils::mmToPx($place_width, 300)/$resize_val, 300);
                           $h=Utils::pxToMm(Utils::mmToPx($place_height, 300)/$resize_val, 300);
            
            
                        echo  $w;
                        echo $h;
                        die();*/
            $image_data = Utils::makeTextImage($this->text_label, $place_width, $place_height, $this->text_color, $this->font, $this->margin);
            file_put_contents($img_path, $image_data);
        }
        $size = getimagesize($img_path);
        //$img_path=UserUrl::photobookPhotos(false, $this->photobook_id, $this->user_id).'/'.UserUrl::imageFile($this->photo_id, $this->image_size);
        $image_real_width = $size[0];
        $image_real_height = $size[1];
        $thumb_width = $this->place_width;
        $thumb_height = $this->place_height;
        $width = $image_real_width;
        $height = $image_real_height;
        $original_aspect = $width / $height;
        $thumb_aspect = $thumb_width / $thumb_height;
        if ($original_aspect >= $thumb_aspect) {
            $new_height = $thumb_height;
            $new_width = $width / ($height / $thumb_height);
        } else {
            // If the thumbnail is wider than the image
            $new_width = $thumb_width;
            $new_height = $height / ($width / $thumb_width);
        }
        $image_posX = 0 - ($new_width - $thumb_width) / 2;
        $image_posY = 0 - ($new_height - $thumb_height) / 2;
        $image_real_width = $new_width;
        $image_real_height = $new_height;
        $uid = rand(1, 99999999999999999);
        $lastModified = filemtime($img_path);
        if ($this->view == 'svg') {
            // <path fill="#999999" fill-opacity="1" clip-path="url(#clip-path-{uid})" d="M 0 0 h {width}  v {height}  h -{width}  v -{height}  z"/>
            $content = '<g xmlns:xlink="http://www.w3.org/1999/xlink"  class="placeholder text"  transform="translate(-{w2}, -{h2})" width="{width}" height="{height}" clip-path="url(#clip-path-{uid})" >
                        <defs>
                            <clipPath id="clip-path-{uid}">
                                <path d="M 0 0 h {width}  v {height}  h -{width}  v -{height}  z"/>
                            </clipPath>
                        </defs>



                        <g >
                            <g transform="translate({img_pos_x},{img_pos_y}) scale(1,1)" width="{width}" height="{height}" pointer-events="none">
                                <image width="{image_real_width}" height="{image_real_height}" xlink:href="{img_url}"/>
                            </g>
                        </g>

                    </g>';
            $img_url = $img_url . '?v=' . $lastModified;
            if ($this->image_size == UserUrl::IMAGE_THUMB || $this->image_size == UserUrl::IMAGE_SMALL) {
                // $img_path=UserUrl::photobookPhotos(false, $this->photobook_id, $this->user_id).'/'.UserUrl::imageFile($this->photo_id, UserUrl::IMAGE_SMALL);
                $imageData = base64_encode(file_get_contents($img_path));
                $img_url = 'data:image/jpeg' . ';base64,' . $imageData;
            } else {
                if ($this->image_size == UserUrl::IMAGE_ORIGINAL) {
                    $imageData = base64_encode(file_get_contents($img_path));
                    $img_url = 'data:image/jpeg' . ';base64,' . $imageData;
                    //$img_url='http://'.$_SERVER['HTTP_HOST'].UserUrl::photobookPhotos(true, $this->photobook_id, $this->user_id).'/'.UserUrl::imageFile($this->photo_id, $this->image_size);;
                }
            }
            echo Yii::t('app', $content, ['width' => $this->place_width, 'height' => $this->place_height, 'uid' => $uid, 'image_width' => $this->image_width, 'image_height' => $this->image_height, 'image_real_width' => $image_real_width, 'image_real_height' => $image_real_height, 'first_image_real_width' => $image_real_width, 'first_image_real_height' => $image_real_height, 'img_url' => $img_url, 'w2' => $this->place_width / 2, 'h2' => $this->place_height / 2, 'img_pos_x' => $image_posX, 'img_pos_y' => $image_posY]);
        } else {
            if ($this->view == 'json') {
                echo json_encode(['width' => $this->place_width, 'height' => $this->place_height, 'uid' => $uid, 'object_text' => true, 'image_width' => $this->image_width, 'image_height' => $this->image_height, 'image_real_width' => $image_real_width, 'image_real_height' => $image_real_height, 'first_image_real_width' => $image_real_width, 'first_image_real_height' => $image_real_height, 'img_url' => $img_url . '?v=' . $lastModified, 'photo_id' => $this->photo_id, 'w2' => $this->place_width / 2, 'h2' => $this->place_height / 2, 'img_pos_x' => $image_posX, 'img_pos_y' => $image_posY, 'last_modified' => $lastModified]);
            }
        }
    }
Beispiel #7
0
echo Yii::t('app', 'Загрузить подложку паспарту разворота');
?>
                            </div>
                            <input type="file" class="fileupload-padded-passepartout" name="StyleForm[photo]" value="" multiple=""  data-url="<?php 
echo Url::toRoute(['styles-api/upload-padded-passepartout', 'id' => $style->id]);
?>
">
                        </span>
                        </form>
                        <div id="paddedPassepartoutPreview">

                            <?php 
if (file_exists(UserUrl::stylePaddedPassepartout(false, $style->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($style->padded_passepartout_key, UserUrl::IMAGE_THUMB))) {
    ?>
                            <div class="row"><div class="col-lg-3"><div class="thumbnail"><a class="thumbnail"><img src="<?php 
    echo UserUrl::stylePaddedPassepartout(true, $style->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($style->padded_passepartout_key, UserUrl::IMAGE_THUMB);
    ?>
" /></a></div></div></div>
                            <?php 
}
?>
                        </div>
                    </div>


                    <div class="form-group">
                        <div class="">
                            <label>
                                <?php 
echo Yii::t('app', 'Цвет однопиксельной обводки для верхнего левого угла');
?>
Beispiel #8
0
    echo $style->name;
    ?>
"  data-placement="top" data-toggle="tooltip" >
                                        <a href="#" data-url="<?php 
    echo Url::toRoute(['photobook-api/change-style', 'photobook_id' => $model->id, 'style_id' => $style->id]);
    ?>
" class="buttonChangeStyle">
                                            <?php 
    if ($style->thumb_key == 'style_default' || $style->thumb_key == 'default_style_thumb' || empty($style->thumb_key)) {
        ?>
                                                <img class="style-min-thumb pull-right" src="/images/style_default.jpg"/>
                                            <?php 
    } else {
        ?>
                                                <img class="style-min-thumb pull-right" src="<?php 
        echo UserUrl::styleThumb(true, $style->id) . '/' . UserUrl::imageFile($style->thumb_key, UserUrl::IMAGE_THUMB);
        ?>
"/>
                                            <?php 
    }
    ?>
                                            <center><?php 
    echo $style->name;
    ?>
</center>
                                        </a>
                                        <span class="badge" > <i class="fa fa-check"></i> </span>


                                    </div>
                                    <div class="text-for-icon">
Beispiel #9
0
                                    <div class="col-xs-3 col-md-3">

                                        <div class="thumbnail">
                                            <a href="<?php 
        echo Yii::$app->urlManager->createUrl(['covers/edit', 'id' => $cover->id]);
        ?>
" class="thumbnail" style="margin-bottom: 5px;">
                                                <?php 
        if ($cover->thumb == 'style_default' || $cover->thumb == 'default_style_thumb' || empty($cover->thumb)) {
            ?>
                                                    <img class="style-min-thumb" src="/images/style_default.jpg"/>
                                                <?php 
        } else {
            ?>
                                                    <img class="style-min-thumb" src="<?php 
            echo UserUrl::coverThumb(true, $cover->id) . '/' . UserUrl::imageFile($cover->thumb, UserUrl::IMAGE_THUMB);
            ?>
"/>
                                                <?php 
        }
        ?>

                                            </a>

                                            <span><?php 
        echo mb_strtoupper($cover->material_type);
        ?>
 / <?php 
        echo $cover->name;
        ?>
</span>
Beispiel #10
0
 public function changeText($page_index, $text)
 {
     $style = Style::findOne(['id' => $this->style_id, 'delete' => 0]);
     $style->data = json_decode($style->data, true);
     $layouts = $style->data['layouts'];
     $templates = [];
     foreach ($layouts as $key => $layout) {
         foreach ($layout['template_ids'] as $key2 => $template_id) {
             $template = Template::findOne(['id' => $template_id]);
             $data = json_decode($template->json, true);
             if ($template->text_object) {
                 $data_text = json_decode($template->json_text, true);
                 $templates[$template_id] = ['json' => $data, 'json_text' => $data_text, 'count_placeholder' => $template->count_placeholder, 'text_object' => $template->text_object, 'passepartout' => $template->passepartout, 'svg' => $template->svg, 'svg_text' => $template->svg_text, 'pb' => $template->pb];
             } else {
                 $templates[$template_id] = ['json' => $data, 'count_placeholder' => $template->count_placeholder, 'text_object' => $template->text_object, 'passepartout' => $template->passepartout, 'svg' => $template->svg, 'pb' => $template->pb];
             }
         }
     }
     $count_photos = count($this->data['pages'][$page_index]['photos']);
     $template_id = $this->data['pages'][$page_index]['layout']['template_ids']['ph_count_' . $count_photos];
     if (!$templates[$template_id]['text_object']) {
         return ['error' => ['msg' => Yii::t('app', 'Макет не поддерживает текстовый блок')]];
     }
     $page = $this->data['pages'][$page_index];
     if (!empty($page['text']) && $page['text']['text'] != $text || empty($page['text'])) {
         if (!empty($page['text']) && !empty($page['text']['file_id'])) {
             $file_id = $page['text']['file_id'];
             //$file_path=UserUrl::photobookTexts(false, $this->id, $this->user_id ).DIRECTORY_SEPARATOR. UserUrl::imageFile($file_id, UserUrl::IMAGE_ORIGINAL);
             foreach (UserUrl::$IMAGE_SIZE as $key => $size) {
                 $file_delete_path = UserUrl::photobookTexts(false, $this->id, $this->user_id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, $key, 'png');
                 if (file_exists($file_delete_path)) {
                     unlink($file_delete_path);
                 }
             }
         }
         $file_id = AlphaId::id(rand(10000000000, 9999999999999));
         $file_path = UserUrl::photobookTexts(false, $this->id, $this->user_id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_ORIGINAL, 'png');
         $this->data['pages'][$page_index]['text'] = ['text' => $text, 'file_id' => $file_id];
         //$json_text=$templates[$template_id]['json_text'];
     }
     $mapTemplates = $this->getMapTemplates();
     $this->data['pages'][$page_index]['json'] = $this->renderJsonPage($this->data['pages'][$page_index], $mapTemplates, $style);
     $this->data['pages'][$page_index]['svg'] = $this->renderSvgPage($this->data['pages'][$page_index], $mapTemplates, $style);
     $this->data['pages'][$page_index]['svg_thumb'] = $this->renderSvgPage($this->data['pages'][$page_index], $mapTemplates, $style, UserUrl::IMAGE_SMALL);
     if ($this->save()) {
         return ['response' => ['status' => true, 'page' => $this->data['pages'][$page_index]]];
     } else {
         return ['error' => ['msg' => Yii::t('app', 'Не удалось записать в базу-данных')]];
     }
 }
Beispiel #11
0
 public function actionSettings()
 {
     if (Yii::$app->user->isGuest) {
         $this->redirect(Url::toRoute(['intro/index']));
         return;
     }
     if (Yii::$app->user->identity->role == User::ROLE_DEMO) {
         $this->redirect(Url::toRoute(['user/signup-demo']));
         return;
     }
     $this->layout = 'default';
     $less_content = file_get_contents(Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR . 'less' . DIRECTORY_SEPARATOR . 'pb-color-template.less');
     $model = new UserSettingForm();
     if ($model->load(Yii::$app->request->post(), 'UserSettingForm')) {
         if ($model->validate()) {
             $model->user_id = Yii::$app->user->identity->getId();
             $file = UploadedFile::getInstance($model, 'logo_url');
             if ($file) {
                 if ($file->size !== 0) {
                     $model->logo_url = $file;
                 } else {
                     $model->logo_url = null;
                 }
                 if ($file->size !== 0) {
                     $old_file_id = '';
                     $user_setting = UserSetting::findByUserId($model->user_id);
                     if ($user_setting) {
                         $old_file_id = $user_setting->logo_url;
                     }
                     $file_id = AlphaId::id(rand(10000000000, 9999999999999));
                     $file_path = UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_ORIGINAL, 'png');
                     $file->saveAs($file_path);
                     $image = Yii::$app->image->load($file_path);
                     $image->resize(0, 49, Yii\image\drivers\Image::HEIGHT);
                     $image->save(UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_SMALL, 'png'));
                     $model->logo_url = $file_id;
                     if (!empty($old_file_id)) {
                         if (file_exists(UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($old_file_id, UserUrl::IMAGE_ORIGINAL, 'png'))) {
                             unlink(UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($old_file_id, UserUrl::IMAGE_ORIGINAL, 'png'));
                         }
                         if (file_exists(UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($old_file_id, UserUrl::IMAGE_SMALL, 'png'))) {
                             unlink(UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($old_file_id, UserUrl::IMAGE_SMALL, 'png'));
                         }
                     }
                 }
             } else {
                 $model->logo_url = null;
             }
             if (Yii::$app->request->post('defaultLogo', 0) == 1) {
                 $model->logo_url = 'default-logo';
             }
             if ($setting = $model->save()) {
                 Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Настройки успешно сохранены.'));
                 return $this->redirect(Url::toRoute('user/settings'));
             }
         }
     } else {
         if (!$model->loadByUserId(Yii::$app->user->identity->getId())) {
         }
     }
     return $this->render('settings', ['model' => $model, 'less_content' => $less_content]);
 }
 public function actionImageRotate()
 {
     $result = [];
     $this->layout = 'json';
     $ref = Yii::$app->request->get('ref');
     $id = Yii::$app->request->get('id');
     $photo_id = Yii::$app->request->get('photo_id', '');
     $deg = intval(Yii::$app->request->get('deg', 0));
     $page = Yii::$app->request->get('page', -1);
     $place_num = intval(Yii::$app->request->get('place_num', -1));
     if (!empty($id)) {
         $model = new PhotobookForm();
         $user_id = AlphaId::id($ref, true);
         $pb_id = AlphaId::id($id, true);
         if ($model->loadById($pb_id)) {
             $file_path = UserUrl::photobookPhotos(false, $pb_id, $user_id);
             $paths = [];
             $paths[] = $file_path;
             $ext = 'jpg';
             if ($model->isText($photo_id)) {
                 $ext = 'png';
             }
             $photo_o_path = $file_path . DIRECTORY_SEPARATOR . UserUrl::imageFile($photo_id, UserUrl::IMAGE_ORIGINAL, $ext);
             $image = Yii::$app->image->load($photo_o_path);
             $image->rotate($deg);
             $image->save($photo_o_path);
             foreach (UserUrl::$IMAGE_SIZE as $key => $size) {
                 if ($key != UserUrl::IMAGE_ORIGINAL) {
                     $image = Yii::$app->image->load($photo_o_path);
                     $type = Yii\image\drivers\Image::HEIGHT;
                     if ($size['width'] > 0 && $size['height'] > 0) {
                         $type = Yii\image\drivers\Image::AUTO;
                     }
                     if ($size['width'] > 0 && $size['height'] == 0) {
                         $type = Yii\image\drivers\Image::WIDTH;
                     }
                     $file_resize_path = UserUrl::photobookPhotos(false, $pb_id, $user_id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($photo_id, $key, $ext);
                     $image->resize($size['width'], $size['height'], $type);
                     $image->save($file_resize_path);
                     unset($image);
                     $image = null;
                 }
             }
             if ($page < 0 || $place_num < 0) {
                 $result = ['response' => ['status' => true, 'photo_id' => $photo_id]];
             } else {
                 $result = $model->setImagePosAndScale($page, $place_num, 0, 0, 1);
             }
             $last_modified = filemtime($photo_o_path);
             if (!empty($result['response'])) {
                 $result['response']['photo_id'] = $photo_id;
                 $result['response']['page_index'] = $page;
                 $result['response']['place_num'] = $place_num;
                 $result['response']['last_modified'] = $last_modified;
             }
         } else {
             $result = ['error' => ['msg' => Yii::t('app', 'Фотокнига не найдена')]];
         }
     } else {
         $result = ['error' => ['msg' => Yii::t('app', 'Фотокнига не найдена')]];
     }
     return $this->render('json', ['result' => $result]);
 }
Beispiel #13
0
 public function run()
 {
     $img = Html::img(UserUrl::photobookPhotos(true, $this->photobook_id, $this->user_id) . '/' . UserUrl::imageFile($this->photo_id, UserUrl::IMAGE_THUMB), ['data-id' => $this->photo_id]);
     $a = Html::a($img, UserUrl::photobookPhotos(true, $this->photobook_id, $this->user_id) . '/' . UserUrl::imageFile($this->photo_id, UserUrl::IMAGE_MIDDLE), ['class' => 'thumb thumb-' . $this->photo_id, 'data-id' => $this->photo_id, 'data-gallery' => '']);
     echo $a;
 }
Beispiel #14
0
 public function updateCoverBack()
 {
     //Удаляем старую подложку обложки
     foreach (UserUrl::$IMAGE_SIZE as $image_size => $value) {
         $file_path = UserUrl::coverBack(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($this->cover_back, $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::coverBack(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::coverBack(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->cover_back = $file_id;
             if (!$this->save()) {
                 return ['error' => ['msg' => Yii::t('app', 'Ошибка записи в базу-данных')]];
             } else {
                 return ['response' => ['status' => true, 'cover_back' => $file_id, 'cover_back_thumb_url' => UserUrl::coverBack(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', 'Данные не получены')]];
     }
 }
Beispiel #15
0
                                <div class="divider"></div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>



             <div class="bb-item" id="sitem3">
                 <div class="content" >
                     <div class="box">
                         <div  id="coverBackBackground" style="width: 100%; height: 100%; position: absolute;  border-bottom-left-radius: 5px; border-top-left-radius: 5px; background-size: contain; background-image: url('<?php 
echo UserUrl::coverBack(true, $selected_cover->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($selected_cover->cover_back, UserUrl::IMAGE_ORIGINAL, 'png');
?>
');">
                             <div class="bb-custom-wrapper"></div>
                         </div>
                     </div>
                 </div>
             </div>
        </div>

        </div>

    </div>


    public function run()
    {
        $image_posX = 0;
        $image_posY = 0;
        /* $scale=2;
           $image_real_width=$this->place_width*$scale;
           $image_real_height=$this->place_height*$scale;*/
        //$img_path=UserUrl::photobookPhotos(true, $this->photobook_id, $this->user_id).'/'.UserUrl::imageFile($this->photo_id, $this->image_size, $this->ext);
        //$size=getimagesize($img_path);
        //$img_path=UserUrl::photobookPhotos(false, $this->photobook_id, $this->user_id).'/'.UserUrl::imageFile($this->photo_id, $this->image_size);
        $image_real_width = $this->real_width;
        //$size[0];
        $image_real_height = $this->real_height;
        //$size[1];
        $thumb_width = $this->place_width;
        $thumb_height = $this->place_height;
        $width = $image_real_width;
        $height = $image_real_height;
        $original_aspect = $width / $height;
        $thumb_aspect = $thumb_width / $thumb_height;
        if ($original_aspect >= $thumb_aspect) {
            // If image is wider than thumbnail (in aspect ratio sense)
            $new_height = $thumb_height;
            $new_width = $width / ($height / $thumb_height);
        } else {
            // If the thumbnail is wider than the image
            $new_width = $thumb_width;
            $new_height = $height / ($width / $thumb_width);
        }
        $scale = $this->scale;
        $image_posX = 0 - ($new_width * $scale - $thumb_width) / 2;
        $image_posY = 0 - ($new_height * $scale - $thumb_height) / 2;
        $image_real_width = $new_width;
        $image_real_height = $new_height;
        $image_posX = $image_posX - $this->pos_dx;
        $image_posY = $image_posY - $this->pos_dy;
        if ($image_posX > 0) {
            $image_posX = 0;
        }
        if ($image_posY > 0) {
            $image_posY = 0;
        }
        if ($image_posX < 0 - $image_real_width * $scale + $thumb_width) {
            $image_posX = 0 - $image_real_width * $scale + $thumb_width;
        }
        if ($image_posY < 0 - $image_real_height * $scale + $thumb_height) {
            $image_posY = 0 - $image_real_height * $scale + $thumb_height;
        }
        $img_url = UserUrl::photobookPhotos(true, $this->photobook_id, $this->user_id) . '/' . UserUrl::imageFile($this->photo_id, $this->image_size, $this->ext);
        $img_path = UserUrl::photobookPhotos(true, $this->photobook_id, $this->user_id) . '/' . UserUrl::imageFile($this->photo_id, $this->image_size, $this->ext);
        $uid = rand(1, 99999999999999999);
        $lastModified = $this->mtime;
        //filemtime($img_path);
        if ($this->view == 'svg') {
            $border = '';
            if ($this->image_size !== UserUrl::IMAGE_ORIGINAL) {
                $border = '<path stroke-width="0.5"  fill="transparent"   stroke="' . $this->passpartu_left_top_border_color . '"  d="M 0 {height} L 0 0  L {width} 0"/>
                     <path stroke-width="0.5" fill="transparent"   stroke="' . $this->passpartu_right_bottom_border_color . '"  d="M {width} 0  L {width} {height}  L 0 {height}"/>';
            }
            $content = '<g xmlns:xlink="http://www.w3.org/1999/xlink"  class="placeholder"  transform="translate(-{w2}, -{h2})" width="{width}" height="{height}" clip-path="url(#clip-path-{uid})" >
                        <defs>
                            <clipPath id="clip-path-{uid}">
                                <path d="M 0 0 h {width}  v {height}  h -{width}  v -{height}  z"/>
                            </clipPath>
                        </defs>




                        <path fill="#ffffff" fill-opacity="1" clip-path="url(#clip-path-{uid})" d="M 0 0 h {width}  v {height}  h -{width}  v -{height}  z"/>

                        <g >
                            <g transform="translate({img_pos_x},{img_pos_y}) scale({scale},{scale})" width="{width}" height="{height}" pointer-events="none">
                                <image width="{image_real_width}" height="{image_real_height}" xlink:href="{img_url}"/>

                            </g>

                            ' . $border . '
                        </g>



                    </g>';
            //stroke-opacity="0.5"
            $img_url = $img_url . '?v=' . $lastModified;
            $mime_type = "image/jpeg";
            if ($this->ext == 'png') {
                $mime_type = "image/png";
            }
            if ($this->image_size == UserUrl::IMAGE_THUMB || $this->image_size == UserUrl::IMAGE_SMALL) {
                // $img_path=UserUrl::photobookPhotos(false, $this->photobook_id, $this->user_id).'/'.UserUrl::imageFile($this->photo_id, UserUrl::IMAGE_SMALL);
                $imageData = base64_encode(file_get_contents($img_path));
                $img_url = 'data:' . $mime_type . ';base64,' . $imageData;
            } else {
                if ($this->image_size == UserUrl::IMAGE_ORIGINAL) {
                    $imageData = base64_encode(file_get_contents($img_path));
                    $img_url = 'data:' . $mime_type . ';base64,' . $imageData;
                    //$img_url='http://'.$_SERVER['HTTP_HOST'].UserUrl::photobookPhotos(true, $this->photobook_id, $this->user_id).'/'.UserUrl::imageFile($this->photo_id, $this->image_size);;
                }
            }
            echo Yii::t('app', $content, ['width' => $this->place_width, 'height' => $this->place_height, 'uid' => $uid, 'image_width' => $this->image_width, 'image_height' => $this->image_height, 'image_real_width' => $image_real_width, 'image_real_height' => $image_real_height, 'first_image_real_width' => $image_real_width, 'first_image_real_height' => $image_real_height, 'scale' => $scale, 'img_url' => $img_url, 'w2' => $this->place_width / 2, 'h2' => $this->place_height / 2, 'img_pos_x' => $image_posX, 'img_pos_y' => $image_posY]);
        } else {
            if ($this->view == 'json') {
                echo json_encode(['width' => $this->place_width, 'height' => $this->place_height, 'uid' => $uid, 'image_width' => $this->image_width, 'image_height' => $this->image_height, 'image_real_width' => $image_real_width, 'image_real_height' => $image_real_height, 'first_image_real_width' => $image_real_width, 'first_image_real_height' => $image_real_height, 'scale' => $scale, 'img_url' => $img_url . '?v=' . $lastModified, 'photo_id' => $this->photo_id, 'w2' => $this->place_width / 2, 'h2' => $this->place_height / 2, 'img_pos_x' => $image_posX, 'img_pos_y' => $image_posY, 'ext' => $this->ext, 'last_modified' => $lastModified]);
            }
        }
    }
    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);
        }
    }