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; }
?> </title> <?php $this->head(); ?> <!-- <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script> <script src="/js/fabricjs.js"></script>--> <link href="<?php echo UserUrl::cssUrl($this->params['css_file_id']); ?> " rel="stylesheet"> <script src="/frontend/web/glyphicons/scripts/modernizr.js"></script> </head> <body class="fixed-size" data-demo="<?php if ($this->params['demo']) { echo '1'; } else { echo '0'; } ?> "> <?php
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]); }
<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>
?> </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">
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]); } } }
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">
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', 'Не удалось записать в базу-данных')]]; } }
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; }
?> <div class="row"> <?php foreach ($templates as $key => $template) { ?> <div class="col-xs-6 col-md-3"> <div class="thumbnail"> <a href="<?php echo Yii::$app->urlManager->createUrl(['templates/edit', 'id' => $template->id]); ?> " class="thumbnail" style="margin-bottom: 5px;"> <img src="<?php echo UserUrl::templateThumb(true, $template->id) . '.jpg?r=' . rand(0, 9999); ?> " /> </a> <span> <?php echo $template->name; ?> </span> <span class="pull-right"> <i class="fa fa-photo"></i> х <?php echo $template->count_placeholder; ?>
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', 'Данные не получены')]]; } }
<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>
<nav id="navbar" class="navbar navbar-default" role="navigation"> <div class="container-fluid"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="<?php echo Url::home(); ?> "><img src="<?php echo UserUrl::logoUrl($this->params['logo_url'], UserUrl::IMAGE_SMALL, 'png'); ?> " height="49" /></a> </div> <div class="navbar-form navbar-right" > <?php if ($this->params['cart_count'] > 0) { ?> <div class="btn-group">
private function saveCss($css) { $css_file_path = UserUrl::css(false, $this->user_id); $css_file_id = rand(10000000000, 99999999999999); $css_file_id = AlphaId::id($css_file_id); file_put_contents($css_file_path . DIRECTORY_SEPARATOR . $css_file_id . '.css', $css); return $css_file_id; }
</div> <div class="col-xs-6"> <h3><?php echo Yii::t('app', 'Просмотр'); ?> </h3> <div class="settings-preview"> <nav role="navigation" class="navbar navbar-default" id="navbar"> <div class="container-fluid"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <a href="#" class="navbar-brand"><img class="logo_url_preview" src="<?php echo UserUrl::logoUrl($model->logo_url, UserUrl::IMAGE_SMALL, 'jpg'); ?> " height="49"/></a> </div> <div class="navbar-form navbar-right"> <div class="btn-group"> <button type="button" class="btn btn-default button-2-line dropdown-toggle" data-toggle="dropdown"> <div class="button-col button-icon "> <i class="glyphicons nameplate "></i> </div> <div class="button-col">
<nav id="navbar" class="navbar navbar-default" role="navigation"> <div class="container-fluid"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="<?php echo Url::home(); ?> "><img src="<?php echo UserUrl::logoUrl($this->params['logo_url'], UserUrl::IMAGE_SMALL, 'png', $this->params['ref_user_id']); ?> " height="49" /></a> </div> <div class="navbar-form navbar-right" > <div class="btn-group"> <button type="button" class="btn btn-primary button-2-line dropdown-toggle" data-toggle="dropdown"> <div class="button-col button-icon "> <i class="glyphicons user"></i> </div> <div class="button-col">
</a> </form> <br/> <form action="<?php echo Url::toRoute(['template-api/upload-fu2', 'id' => $template->id, 'type' => '1_R']); ?> " enctype="multipart/form-data"> <a class="btn btn-primary button-1-line fileinput-button btnUpload1R ladda-button" data-style="zoom-in" data-spinner-color="#993149"> <!--<i class="glyphicon glyphicon-plus"></i>--> <div class="button-col button-icon "> <?php if (file_exists(UserUrl::fu2(false, $template->id, '1_R'))) { ?> <i class="fa fa-check"></i> <?php } else { ?> <i class="fa fa-remove"></i> <?php } ?> </div> <div class="button-col" > <?php echo Yii::t('app', '1_R'); ?>
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); } }
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]); }
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', 'Цвет однопиксельной обводки для верхнего левого угла'); ?>
</div> </div> <div class="row"> <div class="col-xs-2"> <a href="#" class="thumbnail" style="width: 100%; cursor: pointer;"> <?php if (!empty($users_settings[$user->id]) && $users_settings[$user->id]->logo_url != 'default-logo') { ?> <img src="<?php echo UserUrl::logoUrl($users_settings[$user->id]->logo_url, UserUrl::IMAGE_SMALL, 'png', $user->id); ?> " /> <?php } else { ?> <img src="/images/style_default.jpg" /> <?php } ?> </a> </div>
public static function cssUrl($css_file_id, $user_id = null) { if (Yii::$app->user->isGuest && $user_id == null) { return Yii::getAlias('@web') . '/css/pb-theme-color-default.css'; } if ($user_id == null) { $user_id = Yii::$app->user->identity->getId(); } if ($css_file_id !== 'default-logo.png' && !empty($css_file_id)) { return UserUrl::css(true, $user_id) . '/' . $css_file_id . '.css'; } else { return Yii::getAlias('@web') . '/css/pb-theme-color-default.css'; } }
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 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; }
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 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 static function makeTextImage($text, $place_width, $place_height, $text_color = '#000000', $font = null, $margin = 2, $dpi = 300) { $new_text = $text; if (empty($font)) { $font = UserUrl::style(false) . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . 'arial.ttf'; } $max_font_size = 72; //pt $min_font_size = 14; //pt $place_width_px = Utils::mmToPx($place_width, $dpi); $place_height_px = Utils::mmToPx($place_height, $dpi); $margin_px = Utils::mmToPx($margin, $dpi); $max_font_size_px = Utils::ptToPx($max_font_size, $dpi); $current_font_size = $max_font_size; $current_font_size_px = Utils::ptToPx($current_font_size, $dpi); $rect = imagettfbbox($current_font_size_px, 0, $font, $text); $width_px = $rect[2] - $rect[0]; $height_px = $rect[1] - $rect[5]; while ($width_px + $margin_px * 2 > $place_width_px || $height_px + $margin_px * 2 > $place_height_px) { $current_font_size--; //echo 'current_font_size='.$current_font_size; $current_font_size_px = Utils::ptToPx($current_font_size, $dpi); if ($current_font_size <= $min_font_size) { if ($width_px + $margin_px * 2 > $place_width_px) { $new_text = Utils::makeTextBlock($new_text, $font, $current_font_size_px, $place_width_px); } } $rect = imagettfbbox($current_font_size_px, 0, $font, $new_text); //echo 'place_width_px='.$place_width_px.'<br/>'; //echo 'place_height_px='.$place_height_px.'<br/>'; //print_r($rect); $width_px = $rect[2] - $rect[0]; $height_px = $rect[1] - $rect[5]; } $im = imagecreatetruecolor($place_width_px, $place_height_px); $backgroundColor = imagecolorallocatealpha($im, 0, 0, 0, 127); imagefill($im, 0, 0, $backgroundColor); $box = new Box($im); $box->setFontFace($font); // http://www.dafont.com/franchise.font $box->setFontColor(Utils::hexColorToArray($text_color)); $box->setFontSize($current_font_size_px); $box->setLeading(1); $box->setBox($margin_px, $margin_px, $place_width_px - $margin_px * 2, $place_height_px - $margin_px * 2); $box->setTextAlign('center', 'center'); $box->draw($new_text); // header("Content-type: image/png"); imagesavealpha($im, TRUE); ob_start(); //Stdout --> buffer imagepng($im); $img = ob_get_contents(); //store stdout in $img2 ob_end_clean(); //clear buffer imagedestroy($im); return $img; }