function generateThumbnail($originalImgPath, $thumbDir, $prefix, $thumbWidth = 0, $thumbHeight = 0, $type = 'resize', $typeParams = array(), $filters = array()) { $thumbSize = AriImageHelper::getThumbnailDimension($originalImgPath, $thumbWidth, $thumbHeight); if (!$thumbSize['w'] || !$thumbSize['h'] || !@is_readable($originalImgPath)) return null; $width = $thumbSize['w']; $height = $thumbSize['h']; $path_parts = pathinfo($originalImgPath); $thumbName = AriImageHelper::generateThumbnailFileName($prefix, $originalImgPath, $width, $height, $type); $thumbImgPath = $thumbDir . DS . $thumbName; if (@file_exists($thumbImgPath) && @filemtime($thumbImgPath) > @filemtime($originalImgPath)) return $thumbName; if (!AriImageHelper::initAsido()) return ; $thumbImg = Asido::image($originalImgPath, $thumbImgPath); $needResize = true; if ($type == 'crop') { Asido::crop( $thumbImg, intval(AriUtils::getParam($typeParams, 'x', 0), 10), intval(AriUtils::getParam($typeParams, 'y', 0), 10), $width ? $width : $height, $height ? $height : $width ); $needResize = false; } else if ($type == 'cropresize') { Asido::crop( $thumbImg, intval(AriUtils::getParam($typeParams, 'x', 0), 10), intval(AriUtils::getParam($typeParams, 'y', 0), 10), intval(AriUtils::getParam($typeParams, 'width', 0), 10), intval(AriUtils::getParam($typeParams, 'height', 0), 10) ); } if ($filters) { if (AriUtils::parseValueBySample( AriUtils::getParam($filters, 'grayscale', false), false) ) { Asido::grayscale($thumbImg); } $rotateFilter = AriUtils::getParam($filters, 'rotate'); if (is_array($rotateFilter) && AriUtils::parseValueBySample( AriUtils::getParam($rotateFilter, 'enable', false), false) ) { $angle = 0; $rotateType = AriUtils::getParam($rotateFilter, 'type', 'fixed'); if ($rotateType == 'random') { $startAngle = intval(AriUtils::getParam($rotateFilter, 'startAngle', 0), 10); $endAngle = intval(AriUtils::getParam($rotateFilter, 'endAngle', 0), 10); $angle = rand($startAngle, $endAngle); } else { $angle = intval(AriUtils::getParam($rotateFilter, 'angle', 0), 10); } $angle = $angle % 360; if ($angle != 0) { Asido::rotate($thumbImg, $angle); } } } if ($needResize) { if (!$width) Asido::height($thumbImg, $height); else if (!$height) Asido::width($thumbImg, $width); else Asido::resize($thumbImg, $width, $height, ASIDO_RESIZE_STRETCH); } $thumbImg->save(ASIDO_OVERWRITE_ENABLED); return $thumbName; }
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); } } }