Exemplo n.º 1
0
    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]);
    }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 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;
 }