Example #1
0
 protected function renderType(&$context)
 {
     $params = $this->slider->params;
     N2Loader::import('libraries.image.color');
     $width = intval($context['width']);
     $height = intval($context['height']);
     $context['backgroundSize'] = $params->get('background-size');
     $context['backgroundAttachment'] = $params->get('background-fixed') ? 'fixed' : 'scroll';
     $borderWidth = $params->get('border-width');
     $borderColor = $params->get('border-color');
     $context['borderRadius'] = $params->get('border-radius') . 'px';
     $padding = N2Parse::parse($params->get('padding'));
     $context['paddingt'] = $padding[0] . 'px';
     $context['paddingr'] = $padding[1] . 'px';
     $context['paddingb'] = $padding[2] . 'px';
     $context['paddingl'] = $padding[3] . 'px';
     if ($context['canvas']) {
         $width += 2 * $borderWidth + $padding[1] + $padding[3];
         $height += 2 * $borderWidth + $padding[0] + $padding[2];
         $context['width'] = $width . "px";
         $context['height'] = $height . "px";
     }
     $context['border'] = $borderWidth . 'px';
     $rgba = N2Color::hex2rgba($borderColor);
     $context['borderrgba'] = 'RGBA(' . $rgba[0] . ',' . $rgba[1] . ',' . $rgba[2] . ',' . round($rgba[3] / 127, 2) . ')';
     $context['borderhex'] = '#' . substr($borderColor, 0, 6);
     $width = $width - ($padding[1] + $padding[3]) - $borderWidth * 2;
     $height = $height - ($padding[0] + $padding[2]) - $borderWidth * 2;
     $context['inner1height'] = $height . 'px';
     $context['canvaswidth'] = $width . "px";
     $context['canvasheight'] = $height . "px";
     N2LESS::addFile(N2Filesystem::translate(dirname(__FILE__) . NDS . 'style.less'), $this->slider->cacheId, $context, NEXTEND_SMARTSLIDER_ASSETS . '/less' . NDS);
 }
Example #2
0
 public function parseBorder($v)
 {
     $border = explode('|*|', $v);
     $style = 'border-width: ' . $border[0] . 'px';
     $style .= 'border-style: ' . $border[1] . ';';
     $rgba = N2Color::hex2rgba($border[2]);
     $style .= 'border-color: #' . substr($border[2], 0, 6) . "; border-color: RGBA(" . $rgba[0] . ',' . $rgba[1] . ',' . $rgba[2] . ',' . round($rgba[3] / 127, 2) . ');';
     return $style;
 }
Example #3
0
 /**
  * @param $slide N2SmartSliderSlide
  *
  * @return string
  */
 public function make($slide)
 {
     $dynamicHeight = intval($this->slider->params->get('dynamic-height', 0));
     $backgroundImageOpacity = min(100, max(0, $slide->parameters->get('backgroundImageOpacity', 100))) / 100;
     if ($slide->hasGenerator()) {
         $rawBackgroundImage = $slide->parameters->get('backgroundImage', '');
         $backgroundImage = $slide->fill($rawBackgroundImage);
         $imageData = N2ImageManager::getImageData($rawBackgroundImage);
         $imageData['desktop-retina']['image'] = $slide->fill($imageData['desktop-retina']['image']);
         $imageData['tablet']['image'] = $slide->fill($imageData['tablet']['image']);
         $imageData['tablet-retina']['image'] = $slide->fill($imageData['tablet-retina']['image']);
         $imageData['mobile']['image'] = $slide->fill($imageData['mobile']['image']);
         $imageData['mobile-retina']['image'] = $slide->fill($imageData['mobile-retina']['image']);
     } else {
         $backgroundImage = $slide->fill($slide->parameters->get('backgroundImage', ''));
         $imageData = N2ImageManager::getImageData($backgroundImage);
     }
     $sizes = $this->slider->assets->sizes;
     $backgroundColor = '';
     $color = $slide->parameters->get('backgroundColor', '');
     if (strlen($color) == 8 && substr($color, 6, 2) != '00') {
         $backgroundColor = 'background-color: #' . substr($color, 0, 6) . ';';
         if (!class_exists('N2Color')) {
             N2Loader::import("libraries.image.color");
         }
         $rgba = N2Color::hex2rgba($color);
         $rgba[3] = round($rgba[3] / 127, 2);
         $backgroundColor .= "background-color: RGBA({$rgba[0]}, {$rgba[1]}, {$rgba[2]}, {$rgba[3]});";
     }
     if (empty($backgroundImage)) {
         $src = N2Image::base64Transparent();
     } else {
         $src = $backgroundImage;
     }
     $alt = $slide->parameters->get('backgroundAlt', '');
     $title = $slide->parameters->get('backgroundTitle', '');
     $fillMode = $slide->parameters->get('backgroundMode', 'default');
     if ($fillMode == 'default') {
         $fillMode = $this->slider->params->get('backgroundMode', 'fill');
     }
     if ($dynamicHeight) {
         return $this->simple($backgroundColor, $backgroundImageOpacity, $src, $imageData, $alt, $title, $sizes);
     }
     switch ($fillMode) {
         case 'fit':
             return $this->fit($backgroundColor, $backgroundImageOpacity, $src, $imageData, $alt, $title, $sizes);
         case 'stretch':
             return $this->stretch($backgroundColor, $backgroundImageOpacity, $src, $imageData, $alt, $title);
         case 'center':
             return $this->center($backgroundColor, $backgroundImageOpacity, $src, $imageData);
         case 'tile':
             return $this->tile($backgroundColor, $backgroundImageOpacity, $src, $imageData);
     }
     return $this->fill($backgroundColor, $backgroundImageOpacity, $src, $imageData, $alt, $title, $sizes);
 }
Example #4
0
 static function render($slider, $id, $params)
 {
     $html = '';
     $play = $params->get(self::$key . 'play-image');
     $playColor = $params->get(self::$key . 'play-color');
     if (empty($play)) {
         $play = $params->get(self::$key . 'play');
         if ($play == -1) {
             $play = null;
         } elseif ($play[0] != '$') {
             $play = N2Uri::pathToUri(dirname(__FILE__) . '/image/play/' . $play);
         }
     }
     if ($params->get(self::$key . 'mirror')) {
         $pause = str_replace('image/play/', 'image/pause/', $play);
         $pauseColor = $playColor;
     } else {
         $pause = $params->get(self::$key . 'pause-image');
         $pauseColor = $params->get(self::$key . 'pause-color');
         if (empty($pause)) {
             $pause = $params->get(self::$key . 'pause');
             if ($pause == -1) {
                 $pause = null;
             } elseif ($pause[0] != '$') {
                 $pause = N2Uri::pathToUri(dirname(__FILE__) . '/image/pause/' . $pause);
             }
         }
     }
     $ext = pathinfo($play, PATHINFO_EXTENSION);
     if (substr($play, 0, 1) == '$' && $ext == 'svg') {
         list($color, $opacity) = N2Color::colorToSVG($playColor);
         $play = 'data:image/svg+xml;base64,' . base64_encode(str_replace(array('fill="#FFF"', 'opacity="1"'), array('fill="#' . $color . '"', 'opacity="' . $opacity . '"'), N2Filesystem::readFile(N2ImageHelper::fixed($play, true))));
     } else {
         $play = N2ImageHelper::fixed($play);
     }
     $ext = pathinfo($pause, PATHINFO_EXTENSION);
     if (substr($pause, 0, 1) == '$' && $ext == 'svg') {
         list($color, $opacity) = N2Color::colorToSVG($pauseColor);
         $pause = 'data:image/svg+xml;base64,' . base64_encode(str_replace(array('fill="#FFF"', 'opacity="1"'), array('fill="#' . $color . '"', 'opacity="' . $opacity . '"'), N2Filesystem::readFile(N2ImageHelper::fixed($pause, true))));
     } else {
         $pause = N2ImageHelper::fixed($pause);
     }
     if ($play && $pause) {
         N2CSS::addFile(N2Filesystem::translate(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'image' . DIRECTORY_SEPARATOR . 'style.css'), $id);
         N2JS::addFile(N2Filesystem::translate(dirname(__FILE__) . '/image/autoplay.js'), $id);
         list($displayClass, $displayAttributes) = self::getDisplayAttributes($params, self::$key);
         $styleClass = N2StyleRenderer::render($params->get(self::$key . 'style'), 'heading', $slider->elementId, 'div#' . $slider->elementId . ' ');
         list($style, $attributes) = self::getPosition($params, self::$key);
         N2JS::addInline('new NextendSmartSliderWidgetAutoplayImage("' . $id . '", ' . floatval($params->get(self::$key . 'responsive-desktop')) . ', ' . floatval($params->get(self::$key . 'responsive-tablet')) . ', ' . floatval($params->get(self::$key . 'responsive-mobile')) . ');');
         $html = N2Html::tag('div', $displayAttributes + $attributes + array('class' => $displayClass . $styleClass . 'nextend-autoplay nextend-autoplay-image', 'style' => $style), N2Html::image($play, '', array('class' => 'nextend-autoplay-play n2-ow')) . N2Html::image($pause, '', array('class' => 'nextend-autoplay-pause n2-ow')));
     }
     return $html;
 }
Example #5
0
 /**
  * @param $v
  *
  * @return string
  */
 public function parseTshadow($v)
 {
     $v = N2Parse::parse($v);
     $rgba = N2Color::hex2rgba($v[3]);
     if ($v[0] == 0 && $v[1] == 0 && $v[2] == 0) {
         return 'text-shadow: none;';
     }
     return 'text-shadow: ' . $v[0] . 'px ' . $v[1] . 'px ' . $v[2] . 'px RGBA(' . $rgba[0] . ',' . $rgba[1] . ',' . $rgba[2] . ',' . round($rgba[3] / 127, 2) . ');';
 }
Example #6
0
 protected function _resizeImage($filePath, $extension, $imagePath, $targetWidth, $targetHeight, $mode, $backgroundColor, $originalFileModified = null)
 {
     if ($extension == 'png') {
         $image = @imagecreatefrompng($imagePath);
     } else {
         if ($extension == 'jpg') {
             $image = @imagecreatefromjpeg($imagePath);
             if (function_exists("exif_read_data")) {
                 $exif = exif_read_data($imagePath);
                 $rotated = $this->getOrientation($exif, $image);
                 if ($rotated) {
                     imagedestroy($image);
                     $image = $rotated;
                 }
             }
         }
     }
     if ($image) {
         $originalWidth = imagesx($image);
         $originalHeight = imagesy($image);
         if ($rotated || $originalWidth != $targetWidth || $originalHeight != $targetHeight) {
             $newImage = imagecreatetruecolor($targetWidth, $targetHeight);
             if ($extension == 'png') {
                 imagesavealpha($newImage, true);
                 imagealphablending($newImage, false);
                 $transparent = imagecolorallocatealpha($newImage, 255, 255, 255, 127);
                 imagefilledrectangle($image, 0, 0, $targetWidth, $targetHeight, $transparent);
             } else {
                 if ($extension == 'jpg' && $backgroundColor) {
                     $rgb = N2Color::hex2rgb($backgroundColor);
                     $background = imagecolorallocate($newImage, $rgb[0], $rgb[1], $rgb[2]);
                     imagefilledrectangle($newImage, 0, 0, $targetWidth, $targetHeight, $background);
                 }
             }
             list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $this->imageMode($targetWidth, $targetHeight, $originalWidth, $originalHeight, $mode);
             imagecopyresampled($newImage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
             imagedestroy($image);
         } else {
             $newImage = $image;
         }
         if ($extension == 'png') {
             imagepng($newImage, $filePath);
         } else {
             if ($extension == 'jpg') {
                 imagejpeg($newImage, $filePath, 100);
             }
         }
         imagedestroy($newImage);
         return true;
     }
     throw new Exception('Unable to resize image: ' . $imagePath);
 }
 private static function getHTML($id, &$params, $animation, $side, $image, $displayClass, $displayAttributes, $styleClass, $color = 'ffffffcc', $hover = 0, $hoverColor = 'ffffffcc')
 {
     list($style, $attributes) = self::getPosition($params, self::$key . $side . '-');
     $imageHover = null;
     $ext = pathinfo($image, PATHINFO_EXTENSION);
     if (substr($image, 0, 1) == '$' && $ext == 'svg') {
         list($color, $opacity) = N2Color::colorToSVG($color);
         $content = N2Filesystem::readFile(N2ImageHelper::fixed($image, true));
         $image = 'data:image/svg+xml;base64,' . base64_encode(str_replace(array('fill="#FFF"', 'opacity="1"'), array('fill="#' . $color . '"', 'opacity="' . $opacity . '"'), $content));
         if ($hover) {
             list($color, $opacity) = N2Color::colorToSVG($hoverColor);
             $imageHover = 'data:image/svg+xml;base64,' . base64_encode(str_replace(array('fill="#FFF"', 'opacity="1"'), array('fill="#' . $color . '"', 'opacity="' . $opacity . '"'), $content));
         }
     } else {
         $image = N2ImageHelper::fixed($image);
     }
     if ($imageHover === null) {
         $image = N2Html::image($image, 'arrow');
     } else {
         $image = N2Html::image($image, 'arrow', array('class' => 'n2-arrow-normal-img')) . N2Html::image($imageHover, 'arrow', array('class' => 'n2-arrow-hover-img'));
     }
     if ($animation == 'none' || $animation == 'fade') {
         return N2Html::tag('div', $displayAttributes + $attributes + array('id' => $id . '-arrow-' . $side, 'class' => $displayClass . $styleClass . 'nextend-arrow n2-ib nextend-arrow-' . $side . '  nextend-arrow-animated-' . $animation, 'style' => $style), $image);
     }
     return N2Html::tag('div', $displayAttributes + $attributes + array('id' => $id . '-arrow-' . $side, 'class' => $displayClass . 'nextend-arrow n2-ib nextend-arrow-animated nextend-arrow-animated-' . $animation . ' nextend-arrow-' . $side, 'style' => $style), N2Html::tag('div', array('class' => $styleClass . ' n2-resize'), $image) . N2Html::tag('div', array('class' => $styleClass . ' n2-active n2-resize'), $image));
 }