function generateThumbnail($slide, $thumbWidth, $thumbHeight, $thumbPath, $cachePath, $disableOriginal = false) { $img = $slide['src']; $imgUri = $slide['image']; $thumbFile = null; if ($thumbPath) { $pathInfo = pathinfo($img); $thumbImg = $pathInfo['dirname'] . DS . str_replace(array('{$fileName}', '{$baseFileName}'), array($pathInfo['basename'], basename($pathInfo['basename'], '.' . $pathInfo['extension'])), $thumbPath); if (@file_exists(JPATH_ROOT . DS . $thumbImg) && @is_file(JPATH_ROOT . DS . $thumbImg)) { $thumbFile = $thumbImg; } } if (is_null($thumbFile)) { $thumbName = AriImageHelper::generateThumbnail(JPATH_ROOT . DS . $img, JPATH_ROOT . DS . $cachePath, 'acc', $thumbWidth, $thumbHeight); if ($thumbName) { $thumbFile = $cachePath . DS . $thumbName; } else { $thumbFile = $img; } } $slide['src'] = $thumbFile; $slide['image'] = str_replace('\\', '/', $thumbFile); if (!$disableOriginal && empty($slide['link'])) { $slide['link'] = $imgUri; } $thumbSize = AriImageHelper::getThumbnailDimension(JPATH_ROOT . DS . $thumbFile, $thumbWidth, $thumbHeight); if (!empty($thumbSize['w'])) { $slide['width'] = $thumbSize['w']; } if (!empty($thumbSize['h'])) { $slide['height'] = $thumbSize['h']; } return $slide; }
function getImages($content, $params) { $images = array(); $matches = array(); $clearContent = strip_tags($content, '<img>'); preg_match_all('/<img.*?>/i', $clearContent, $matches); if (!empty($matches[0])) { $prefix = $this->_prefix; $cacheDir = $this->_cacheDir; $cacheUri = $cacheDir; if (strpos($cacheUri, JPATH_ROOT . DS) === 0) $cacheUri = substr($cacheUri, strlen(JPATH_ROOT . DS)); $cacheUri = str_replace(DS, '/', $cacheUri) . '/'; $i = 0; $thumbCount = $params['thumbCount']; $generateThumbs = $params['generateThumbs']; $thumbType = $params['thumbType']; $thumbTypeParams = $params['thumbTypeParams']; $thumbFilters = $params['thumbFilters']; $ignoreEmptyDim = $params['ignoreEmptyDim']; $ignoreRemote = $params['ignoreRemote']; $thumbAttrs = null; foreach ($matches[0] as $match) { $attrs = AriHtmlHelper::extractAttrs($match); $src = AriUtils2::getParam($attrs, 'src', ''); if (empty($src)) continue ; if ($ignoreRemote && strpos($src, 'http') === 0 && strpos($src, JURI::root()) === false) continue ; $thumbWidth = $params['thumbWidth']; $thumbHeight = $params['thumbHeight']; if (!empty($attrs['style']) || !empty($attrs['width']) || !empty($attrs['height'])) { $imgStyles = !empty($attrs['style']) ? AriHtmlHelper::extractInlineStyles($attrs['style']) : null; $styleWidth = isset($imgStyles['width']) ? intval($imgStyles['width'], 10) : 0; $styleHeight = isset($imgStyles['height']) ? intval($imgStyles['height'], 10) : 0; if (!empty($styleWidth)) $thumbWidth = $styleWidth; else if (!empty($attrs['width'])) $thumbWidth = @intval($attrs['width'], 10); if (!empty($styleHeight)) $thumbHeight = $styleHeight; else if (!empty($attrs['height'])) $thumbHeight = @intval($attrs['height'], 10); } $title = AriUtils2::getParam($attrs, 'alt', AriUtils2::getParam($attrs, 'title', '')); $thumbAttrs = array('alt' => $title); $imgAttrs = array('title' => $title, 'href' => $src); if ($params['class']) $imgAttrs['class'] = $params['class']; $image = array( 'image' => array( 'original' => $match, 'originalAttributes' => $attrs, 'attributes' => null, 'title' => $title, 'src' => $src), 'thumb' => array( 'src' => $src, 'width' => $thumbWidth, 'height' => $thumbHeight, 'atttributes' => null, 'asOriginal' => false ) ); $thumbSrc = $src; if ($generateThumbs && ($thumbCount < 1 || $i < $thumbCount)) { $imgPath = $src; $baseUrl = strtolower(JURI::base()); if (strpos(strtolower($imgPath), $baseUrl) === 0) $imgPath = substr($imgPath, strlen($baseUrl)); if (!preg_match('/^(http|https|ftp):\/\//i', $imgPath)) { $imgPath = JPATH_ROOT . DS . str_replace('/', DS, $imgPath); $originalSize = @getimagesize($imgPath); if ((!$ignoreEmptyDim || isset($attrs['width']) || isset($attrs['height'])) && (!is_array($originalSize) || count($originalSize) < 2 || (($thumbWidth > 0 && $originalSize[0] != $thumbWidth) || ($thumbHeight > 0 && $originalSize[1] != $thumbHeight)))) { $thumbFile = AriImageHelper::generateThumbnail( $imgPath, $cacheDir, $prefix, $thumbWidth, $thumbHeight, $thumbType, $thumbTypeParams, $thumbFilters); if ($thumbFile) { $size = @getimagesize($cacheDir . DS . $thumbFile); if (is_array($size) && count($size) > 1) { $image['thumb']['width'] = $size[0]; $image['thumb']['height'] = $size[1]; } $image['thumb']['src'] = $cacheUri . $thumbFile; } } else { $image['thumb']['asOriginal'] = true; } } } $thumbAttrs['src'] = $image['thumb']['src']; if ($image['thumb']['width'] > 0) $thumbAttrs['width'] = $image['thumb']['width']; if ($image['thumb']['height'] > 0) $thumbAttrs['height'] = $image['thumb']['height']; if (isset($attrs['border'])) $thumbAttrs['border'] = $attrs['border']; $image['thumb']['attributes'] = $thumbAttrs; $image['image']['attributes'] = $imgAttrs; $images[] = $image; ++$i; } } return $images; }
function generateThumbnail($slide, $thumbWidth, $thumbHeight, $thumbPath, $cachePath, $defLink = null) { $img = $slide['src']; $imgUri = $slide['image']; $thumbFile = null; if ($thumbPath) { $pathInfo = pathinfo($img); $thumbImg = $pathInfo['dirname'] . DS . str_replace('{$fileName}', $pathInfo['basename'], $thumbPath); if (@file_exists(JPATH_ROOT . DS . $thumbImg) && @is_file(JPATH_ROOT . DS . $thumbImg)) { $thumbFile = $thumbImg; } } if (is_null($thumbFile)) { $thumbName = AriImageHelper::generateThumbnail(JPATH_ROOT . DS . $img, JPATH_ROOT . DS . $cachePath, 'ais', $thumbWidth, $thumbHeight); if ($thumbName) { $thumbFile = $cachePath . DS . $thumbName; } else { $thumbFile = $img; } } $slide['src'] = $thumbFile; $slide['image'] = str_replace('\\', '/', $thumbFile); if (empty($slide['link'])) { $slide['link'] = empty($defLink) ? $imgUri : $defLink; } $thumbSize = AriImageHelper::getThumbnailDimension(JPATH_ROOT . DS . $thumbFile, $thumbWidth, $thumbHeight); if (!empty($thumbSize['w'])) { $slide['width'] = $thumbSize['w']; } if (!empty($thumbSize['h'])) { $slide['height'] = $thumbSize['h']; } return $slide; }
function generateThumbnails($params) { $thumbWidth = $params['thumbWidth']; $thumbHeight = $params['thumbHeight']; $folders = $params['folders']; $cacheDir = $this->_cacheDir; $prefix = $this->_prefix; $thumbPath = $params['thumbPath']; $thumbType = $params['thumbType']; $thumbTypeParams = $params['thumbTypeParams']; $thumbFilters = $params['thumbFilters']; foreach ($folders as $folder) { $files = $this->getImageFiles($folder, $params['fileFilter']); foreach ($files as $file) { $filePath = JPATH_ROOT . DS . $file; if ($thumbPath) { $thumbImagePath = JPATH_ROOT . DS . $folder . DS . str_replace('{$fileName}', basename($file), $thumbPath); if (file_exists($thumbImagePath)) continue ; } AriImageHelper::generateThumbnail( $filePath, $cacheDir, $prefix, $thumbWidth, $thumbHeight, $thumbType, $thumbTypeParams, $thumbFilters); } } }