| Server IP : 195.130.67.5 / Your IP : 216.73.217.154 Web Server : Microsoft-IIS/10.0 System : Windows NT WEBSERVER1 10.0 build 17763 (Windows Server 2016) i586 User : IUSR ( 0) PHP Version : 7.4.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /Old Sites/eadsa/modules/mod_imagescroll/ |
Upload File : |
<?php
/**
* JdvThumbs Class
*
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
class JdvThumbs
{
var $_thumbParams;
function __construct()
{
$this->_thumbParams['width'] = 200;
$this->_thumbParams['height'] = 200;
$this->_thumbParams['quality'] = 100;
$this->_thumbParams['method'] = 'resized';
$this->_thumbParams['alpha'] = 1;
$this->_thumbParams['thumbtype'] = 'jpg';
$this->_thumbParams['sizeon'] = 'both';
$this->_thumbParams['prefix'] = 'thumb';
$this->_thumbParams['thumbsdir'] = 'cache/plg_jdvthumbs';
$this->_thumbParams['replace'] = 0;
$this->_thumbParams['md5'] = 1;
}
function set($param, $value){
$this->_thumbParams[$param] = $value;
}
function get($param){
return $this->_thumbParams[$param];
}
function doThumbnail( $files, $is_abs=false )
{
//global $mainframe;
extract($this->_thumbParams);
if ($thumbtype == 'jpg'){
$thumb_ext = 'jpg';
}else{
$thumb_ext = $file_ext;
}
$files_thumb = array();
$files_src = array();
$thumbsdir = str_replace( array('/', '\\'), DS, $thumbsdir );
$path_dest = JPATH_ROOT . DS . $thumbsdir;
$n = count( $files );
foreach ($files as &$file) {
$www = JURI::base();
if (strpos($www, '://www.') === false){
$www2 = str_replace(array('http://', 'https://'), array('http://www.', 'https://www.'), JURI::base());
}else{
$www2 = str_replace(array('http://www.', 'https://www.'), array('http://', 'https://'), JURI::base());
}
$file = str_replace(array($www, $www2), '', $file);
if (!$is_abs){
$file_url = str_replace( DS, '/', $file );
$file = str_replace( array('/', '\\'), DS, $file );
$file = JPATH_ROOT . DS . $file;
}else{
$file = str_replace( array('/', '\\'), DS, $file );
$file_url = str_replace( JPATH_ROOT, '', $file );
$file_url = str_replace( DS, '/', $file_url );
}
//echo md5( $file );
$filename = basename( $file );
$file_ext = $this->getFileExt( $filename );
$array_ext = array('jpg', 'png');
if (!in_array($file_ext, $array_ext)){
continue;
}
unset($array_ext);
$files_thumb[] = $path_dest . DS . $prefix . ($md5 ? '-' . @md5( $file ) : '') . '.' . $thumb_ext;
//print_r($files_thumb);
//echo $file;
$files_src[] = $file;
if ($this->chkCache( $file, $prefix, $thumb_ext, $replace, $md5 )) {
$n--;
continue;
}
if (!is_file($file)) {
$n--;
continue;
}
// Get new sizes
list($width_source, $height_source) = getimagesize($file);
switch ($sizeon) {
case 'width':
$new_width = $width;
$percent = $width / $width_source;
$new_height = $height_source * $percent;
break;
case 'height':
$new_height = $height;
$percent = $height / $height_source;
$new_width = $width_source * $percent;
break;
default:
if (($width / $height) < ($width_source / $height_source)){
$new_width = $width;
$percent = $width / $width_source;
$new_height = $height_source * $percent;
} else {
$new_height = $height;
$percent = $height / $height_source;
$new_width = $width_source * $percent;
}
}
//echo $width;
if (($new_width < $width_source || $new_height < $height_source)) {
$thumb = imagecreatetruecolor($new_width, $new_height );
} else {
if ($thumbtype == 'jpg' && $file_ext != $thumbtype) {
$thumb = imagecreatetruecolor($width_source, $height_source );
}else{
if (!copy( $file, $path_dest . DS . $prefix . ($md5 ? '-' . @md5( $file ) : '') . '.' . $thumb_ext)) {
$n--;
}
continue;
}
}
switch ($file_ext) {
case 'jpg':
// Set the content prefix header - in this case image/jpeg
//ini_set("memory_limit", "64M");
$source = @imagecreatefromjpeg($file);
break;
case 'png':
$source = @imagecreatefrompng($file);
break;
}
if ($alpha && $file_ext == 'png'){
imagealphablending($thumb, false);
imagesavealpha($thumb, true);
}
if ($method == 'resampled'){
// Resampled
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width_source, $height_source);
} else{
imagecopyresized($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width_source, $height_source);
}
switch ($thumb_ext) {
case 'jpg':
// Set the content prefix header - in this case image/jpeg
header('Content-prefix: image/jpeg');
break;
case 'png':
header('Content-prefix: image/png');
break;
default:
$n--;
continue 2;
break;
}
// Output
switch ($thumb_ext) {
case 'jpg':
imagejpeg($thumb, $path_dest . DS . $prefix . ($md5 ? '-' . @md5( $file ) : '') . '.' . $thumb_ext, $quality);
break;
case 'png':
$q = ($quality - 10) / 100;
imagepng($thumb, $path_dest . DS . $prefix . ($md5 ? '-' . @md5( $file ) : '') . '.' . $thumb_ext, $q, PNG_ALL_FILTERS );
break;
}
// Free up memory
imagedestroy($thumb);
imagedestroy($source);
}
return array( $files_thumb, $files_src );
} // end function doThumbnail
function chkCache( $file, $prefix, $thumb_ext, $replace, $md5 )
{
$filename = basename( $file );
$hash = ($md5 ? '-' . @md5( $file ) : '');
$thumbsdir = $this->get( 'thumbsdir' );
$thumbsdir = str_replace( array('/', '\\'), DS, $thumbsdir );
$path_dest = JPATH_ROOT . DS . $thumbsdir;
if (!JFolder::exists($path_dest)) {
//JFolder::create($path_dest, '0755');
JFolder::create($path_dest);
}
$cachefile = $path_dest . DS . $prefix . $hash . '.' . $thumb_ext;
if (!$replace)
if (is_file( $cachefile )) {
return true;
}
return false;
}
function getFileExt( $filename )
{
$file_extension = strtolower(substr(strrchr($filename,"."),1));
return $file_extension;
}
function getURL( $filename )
{
$path_from_base = str_replace(JPATH_SITE . DS, '', $filename);
$juri_base = JURI::root();
$path_from_base = str_replace($juri_base, '', $path_from_base);
$url = str_replace( DS, '/', $path_from_base );
$url = $juri_base . $url;
return $url;
}
}
?>